]> granicus.if.org Git - clang/commitdiff
Fix rdar://6251437, references to enum constant decls in a block
authorChris Lattner <sabre@nondot.org>
Sun, 28 Sep 2008 05:30:26 +0000 (05:30 +0000)
committerChris Lattner <sabre@nondot.org>
Sun, 28 Sep 2008 05:30:26 +0000 (05:30 +0000)
don't need a BlockDeclRefExpr.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@56766 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaExpr.cpp
test/Sema/block-misc.c

index 07ce6b0b2f0cfa51ee4277be36c541bd0831036e..9a0d0aca0e66d6f74316b520aa3a969dfce8e092 100644 (file)
@@ -432,10 +432,11 @@ Sema::ExprResult Sema::ActOnIdentifierExpr(Scope *S, SourceLocation Loc,
   // within the block, create a normal DeclRefExpr.
   //
   // FIXME: This will create BlockDeclRefExprs for global variables,
-  // function references, enums constants, etc which is suboptimal :) and breaks
+  // function references, etc which is suboptimal :) and breaks
   // things like "integer constant expression" tests.
   //
-  if (!CurBlock || DeclDefinedWithinScope(VD, CurBlock->TheScope, S))
+  if (!CurBlock || DeclDefinedWithinScope(VD, CurBlock->TheScope, S) ||
+      isa<EnumConstantDecl>(VD))
     return new DeclRefExpr(VD, VD->getType(), Loc);
   
   // If we are in a block and the variable is outside the current block,
index 92632f3aaa11818603b946215ff9fe3f84c66f40..77de4a6c9e2cfe0fe57c4fade21cc008bdc2f660 100644 (file)
@@ -48,3 +48,17 @@ int test3() {
        char *^ y; // expected-error {{block pointer to non-function type is invalid}}
 }
 
+
+
+enum {NSBIRLazilyAllocated = 0};
+
+int test4(int argc) {  // rdar://6251437
+  ^{
+    switch (argc) {
+      case NSBIRLazilyAllocated:  // is an integer constant expression.
+      default:
+        break;
+    }
+  }();
+  return 0;
+}