]> granicus.if.org Git - clang/commitdiff
Correctly handle constants that refer to enums.
authorAnders Carlsson <andersca@mac.com>
Tue, 29 Jan 2008 01:28:48 +0000 (01:28 +0000)
committerAnders Carlsson <andersca@mac.com>
Tue, 29 Jan 2008 01:28:48 +0000 (01:28 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@46481 91177308-0d34-0410-b5e6-96231b3b80d8

CodeGen/CGExprConstant.cpp
test/CodeGen/globalinit.c
test/CodeGen/init.c

index da2fef66f03912faf41b71206c4422813e1cf03a..faf2096d28b2012e627a0258e17f69934e1afc07 100644 (file)
@@ -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;
   }
index 13a9e930bd3b4c578bd049f91bb53cb6a19797b4..f868feb24a0ee32bcd0805375044231f49496693 100644 (file)
@@ -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 };
index 77a85fa75c4e3188e020632e063498a2020de9e6..24f887422ddf16a76c16390cb7771dba865fc4a6 100644 (file)
@@ -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
+}