diff options
| author | Anders Carlsson <andersca@mac.com> | 2008-01-29 01:28:48 +0000 |
|---|---|---|
| committer | Anders Carlsson <andersca@mac.com> | 2008-01-29 01:28:48 +0000 |
| commit | 0674a7417f29baaedbcf10259826c42c6ac0d997 (patch) | |
| tree | ab74de00dd893734125155d197272f8dd5be85f6 | |
| parent | 6f2a10e8c961c696a34ffadf666cdd280a5bda4f (diff) | |
| download | bcm5719-llvm-0674a7417f29baaedbcf10259826c42c6ac0d997.tar.gz bcm5719-llvm-0674a7417f29baaedbcf10259826c42c6ac0d997.zip | |
Correctly handle constants that refer to enums.
llvm-svn: 46481
| -rw-r--r-- | clang/CodeGen/CGExprConstant.cpp | 2 | ||||
| -rw-r--r-- | clang/test/CodeGen/globalinit.c | 12 | ||||
| -rw-r--r-- | clang/test/CodeGen/init.c | 4 |
3 files changed, 13 insertions, 5 deletions
diff --git a/clang/CodeGen/CGExprConstant.cpp b/clang/CodeGen/CGExprConstant.cpp index da2fef66f03..faf2096d28b 100644 --- a/clang/CodeGen/CGExprConstant.cpp +++ b/clang/CodeGen/CGExprConstant.cpp @@ -186,6 +186,8 @@ public: const ValueDecl *Decl = E->getDecl(); if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(Decl)) return CGM.GetAddrOfFunctionDecl(FD, false); + if (const EnumConstantDecl *EC = dyn_cast<EnumConstantDecl>(Decl)) + return llvm::ConstantInt::get(EC->getInitVal()); assert(0 && "Unsupported decl ref type!"); return 0; } diff --git a/clang/test/CodeGen/globalinit.c b/clang/test/CodeGen/globalinit.c index 13a9e930bd3..f868feb24a0 100644 --- a/clang/test/CodeGen/globalinit.c +++ b/clang/test/CodeGen/globalinit.c @@ -32,6 +32,12 @@ void booltest2() { static _Bool booltest3 = 4; } -// Braces in a scalar -int a = { 1 }; -int b = { 1, 2 }; +// Scalars in braces. +static int a = { 1 }; +static int b = { 1, 2 }; + +enum { + EnumA, EnumB +}; + +int c[] = { EnumA, EnumB }; diff --git a/clang/test/CodeGen/init.c b/clang/test/CodeGen/init.c index 77a85fa75c4..24f887422dd 100644 --- a/clang/test/CodeGen/init.c +++ b/clang/test/CodeGen/init.c @@ -1,7 +1,7 @@ // RUN: clang -emit-llvm %s void f1() { - // Braces in a scalar + // Scalars in braces. int a = { 1 }; int b = { 1, 2 }; -}
\ No newline at end of file +} |

