aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
authorLuc Van Oostenryck <luc.vanoostenryck@gmail.com>2017-03-20 16:52:20 +0100
committerLuc Van Oostenryck <luc.vanoostenryck@gmail.com>2017-11-17 10:04:37 +0100
commit6877ef587143925e2e63f9eb212a2a41d6f38041 (patch)
tree2c1dabba1a644245ec152a77446189298015c195
parent1b41788fcad539813c5eae176665e15e9a124806 (diff)
downloadsparse-dev-6877ef587143925e2e63f9eb212a2a41d6f38041.tar.gz
llvm: fix get value from initialized symbol
Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
-rw-r--r--sparse-llvm.c27
1 files changed, 13 insertions, 14 deletions
diff --git a/sparse-llvm.c b/sparse-llvm.c
index bc903800..47b7b671 100644
--- a/sparse-llvm.c
+++ b/sparse-llvm.c
@@ -295,6 +295,8 @@ static const char *pseudo_name(pseudo_t pseudo, char *buf)
static LLVMValueRef get_sym_value(struct function *fn, struct symbol *sym)
{
+ const char *name = show_ident(sym->ident);
+ LLVMTypeRef type = symbol_type(sym);
LLVMValueRef result = NULL;
struct expression *expr;
@@ -314,7 +316,7 @@ static LLVMValueRef get_sym_value(struct function *fn, struct symbol *sym)
LLVMSetInitializer(data, LLVMConstString(strdup(s), strlen(s) + 1, true));
result = LLVMConstGEP(data, indices, ARRAY_SIZE(indices));
- break;
+ return result;
}
case EXPR_SYMBOL: {
struct symbol *sym = expr->symbol;
@@ -324,21 +326,18 @@ static LLVMValueRef get_sym_value(struct function *fn, struct symbol *sym)
break;
}
default:
- assert(0);
+ break;
}
- } else {
- const char *name = show_ident(sym->ident);
- LLVMTypeRef type = symbol_type(sym);
+ }
- if (LLVMGetTypeKind(type) == LLVMFunctionTypeKind) {
- result = LLVMGetNamedFunction(fn->module, name);
- if (!result)
- result = LLVMAddFunction(fn->module, name, type);
- } else {
- result = LLVMGetNamedGlobal(fn->module, name);
- if (!result)
- result = LLVMAddGlobal(fn->module, type, name);
- }
+ if (LLVMGetTypeKind(type) == LLVMFunctionTypeKind) {
+ result = LLVMGetNamedFunction(fn->module, name);
+ if (!result)
+ result = LLVMAddFunction(fn->module, name, type);
+ } else {
+ result = LLVMGetNamedGlobal(fn->module, name);
+ if (!result)
+ result = LLVMAddGlobal(fn->module, type, name);
}
return result;