diff options
author | Xi Wang <xi.wang@gmail.com> | 2013-05-21 04:05:19 -0400 |
---|---|---|
committer | Pekka Enberg <penberg@kernel.org> | 2013-05-21 12:21:09 +0300 |
commit | 5b950a99d4a81db8581741def3ea6acf05b0b493 (patch) | |
tree | 2a7bfbd28b699687b559b800553bdc6cc7dd05bd | |
parent | 4858eafe71ea9cd6e61a8ee2883e2cde28430f20 (diff) | |
download | sparse-5b950a99d4a81db8581741def3ea6acf05b0b493.tar.gz |
sparse, llvm: fix struct name generation
Avoid null pointer dereference when ->ident is null (e.g., anonymous
struct). Also, use ->aux to avoid recursion.
Signed-off-by: Xi Wang <xi.wang@gmail.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
-rw-r--r-- | sparse-llvm.c | 9 | ||||
-rw-r--r-- | validation/backend/struct.c | 6 |
2 files changed, 9 insertions, 6 deletions
diff --git a/sparse-llvm.c b/sparse-llvm.c index c32ff7d7..e385d27c 100644 --- a/sparse-llvm.c +++ b/sparse-llvm.c @@ -102,13 +102,10 @@ static LLVMTypeRef sym_struct_type(LLVMModuleRef module, struct symbol *sym) LLVMTypeRef ret; unsigned nr = 0; - sprintf(buffer, "%.*s", sym->ident->len, sym->ident->name); - - ret = LLVMGetTypeByName(module, buffer); - if (ret) - return ret; - + snprintf(buffer, sizeof(buffer), "struct.%s", sym->ident ? sym->ident->name : "anno"); ret = LLVMStructCreateNamed(LLVMGetGlobalContext(), buffer); + /* set ->aux to avoid recursion */ + sym->aux = ret; FOR_EACH_PTR(sym->symbol_list, member) { LLVMTypeRef member_type; diff --git a/validation/backend/struct.c b/validation/backend/struct.c index 1afaf2db..905339af 100644 --- a/validation/backend/struct.c +++ b/validation/backend/struct.c @@ -9,10 +9,16 @@ struct symbol { struct symbol *next_id; }; +struct unnamed { + struct { int x, y; }; +}; + static struct symbol sym; static struct symbol *sym_p; static struct symbol *sym_q = &sym; +static struct unnamed un; + /* * check-name: Struct code generation * check-command: ./sparsec -c $file -o tmp.o |