]> granicus.if.org Git - clang/commitdiff
Fix the address of a label to be properly considered and emitted as a
authorEli Friedman <eli.friedman@gmail.com>
Sun, 25 Jan 2009 01:21:06 +0000 (01:21 +0000)
committerEli Friedman <eli.friedman@gmail.com>
Sun, 25 Jan 2009 01:21:06 +0000 (01:21 +0000)
constant.

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

lib/AST/ExprConstant.cpp
lib/CodeGen/CGExprConstant.cpp
test/CodeGen/const-label-addr.c [new file with mode: 0644]

index 4c242059b52859d6765590041b548fc724430c2e..76bdaa2c8f8389cb2551818c07fdb91a9e5af882 100644 (file)
@@ -215,6 +215,8 @@ public:
   APValue VisitUnaryOperator(const UnaryOperator *E);
   APValue VisitObjCStringLiteral(ObjCStringLiteral *E)
       { return APValue(E, 0); }
+  APValue VisitAddrLabelExpr(AddrLabelExpr *E)
+      { return APValue(E, 0); }
   APValue VisitConditionalOperator(ConditionalOperator *E);
 };
 } // end anonymous namespace
index 9d709d3a509d12960efb75a1c70e1eac993cdb67..0e31cacd1b038c52dba088c4987d314f77825a9f 100644 (file)
@@ -619,6 +619,12 @@ public:
       
       return CGM.GetAddrOfConstantCString(Str, ".tmp");
     }
+    case Expr::AddrLabelExprClass: {
+      assert(CGF && "Invalid address of label expression outside function.");
+      unsigned id = CGF->GetIDForAddrOfLabel(cast<AddrLabelExpr>(E)->getLabel());
+      llvm::Constant *C = llvm::ConstantInt::get(llvm::Type::Int32Ty, id);
+      return llvm::ConstantExpr::getIntToPtr(C, ConvertType(E->getType()));
+    }
     }
     CGM.ErrorUnsupported(E, "constant l-value expression");
     llvm::Type *Ty = llvm::PointerType::getUnqual(ConvertType(E->getType()));
diff --git a/test/CodeGen/const-label-addr.c b/test/CodeGen/const-label-addr.c
new file mode 100644 (file)
index 0000000..1ae74e5
--- /dev/null
@@ -0,0 +1,4 @@
+// RUN: clang %s -emit-llvm -o %t
+int a() {
+A:;static void* a = &&A;
+}