[cfe-commits] r46481 - in /cfe/trunk: CodeGen/CGExprConstant.cpp test/CodeGen/globalinit.c test/CodeGen/init.c
Anders Carlsson
andersca at mac.com
Mon Jan 28 17:28:48 PST 2008
Author: andersca
Date: Mon Jan 28 19:28:48 2008
New Revision: 46481
URL: http://llvm.org/viewvc/llvm-project?rev=46481&view=rev
Log:
Correctly handle constants that refer to enums.
Modified:
cfe/trunk/CodeGen/CGExprConstant.cpp
cfe/trunk/test/CodeGen/globalinit.c
cfe/trunk/test/CodeGen/init.c
Modified: cfe/trunk/CodeGen/CGExprConstant.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/CodeGen/CGExprConstant.cpp?rev=46481&r1=46480&r2=46481&view=diff
==============================================================================
--- cfe/trunk/CodeGen/CGExprConstant.cpp (original)
+++ cfe/trunk/CodeGen/CGExprConstant.cpp Mon Jan 28 19:28:48 2008
@@ -186,6 +186,8 @@
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;
}
Modified: cfe/trunk/test/CodeGen/globalinit.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/globalinit.c?rev=46481&r1=46480&r2=46481&view=diff
==============================================================================
--- cfe/trunk/test/CodeGen/globalinit.c (original)
+++ cfe/trunk/test/CodeGen/globalinit.c Mon Jan 28 19:28:48 2008
@@ -32,6 +32,12 @@
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 };
Modified: cfe/trunk/test/CodeGen/init.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/init.c?rev=46481&r1=46480&r2=46481&view=diff
==============================================================================
--- cfe/trunk/test/CodeGen/init.c (original)
+++ cfe/trunk/test/CodeGen/init.c Mon Jan 28 19:28:48 2008
@@ -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
+}
More information about the cfe-commits
mailing list