]> granicus.if.org Git - clang/commitdiff
Fix the type of predefined identifiers like __func__. Patch by
authorChris Lattner <sabre@nondot.org>
Sat, 12 Jan 2008 08:14:25 +0000 (08:14 +0000)
committerChris Lattner <sabre@nondot.org>
Sat, 12 Jan 2008 08:14:25 +0000 (08:14 +0000)
Eli Friedman!

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

AST/Expr.cpp
CodeGen/CGExpr.cpp
Sema/SemaExpr.cpp
test/Sema/predef.c [new file with mode: 0644]

index e2f6c6210b1e0c6ca29198352aa82bfd1685693a..61b02c3e717cfe3c594567cf05cd210626b382f0 100644 (file)
@@ -372,6 +372,8 @@ Expr::isLvalueResult Expr::isLvalue() const {
     return LV_Valid;
   case ObjCIvarRefExprClass: // ObjC instance variables are lvalues.
     return LV_Valid;
+  case PreDefinedExprClass:
+    return LV_Valid;
   default:
     break;
   }
@@ -430,6 +432,8 @@ bool Expr::hasStaticStorage() const {
   }
   case ArraySubscriptExprClass:
     return cast<ArraySubscriptExpr>(this)->getBase()->hasStaticStorage();
+  case PreDefinedExprClass:
+    return true;
   }
 }
 
index 8bc97a9d0af50508a68b44e3619c0df87f81b95a..0fe25c8d168a129dd07100fc9f3cb941200c81ac 100644 (file)
@@ -340,9 +340,6 @@ LValue CodeGenFunction::EmitPreDefinedLValue(const PreDefinedExpr *E) {
   C = new llvm::GlobalVariable(C->getType(), true, 
                                llvm::GlobalValue::InternalLinkage,
                                C, GlobalVarName, CurFn->getParent());
-  llvm::Constant *Zero = llvm::Constant::getNullValue(llvm::Type::Int32Ty);
-  llvm::Constant *Zeros[] = { Zero, Zero };
-  C = llvm::ConstantExpr::getGetElementPtr(C, Zeros, 2);
   return LValue::MakeAddr(C);
 }
 
index a6808f83a7110f9c80f181f5144d45998f8cecce..88ee864b24ec88ed292ab83e813f3f867ba05195 100644 (file)
@@ -128,8 +128,13 @@ Sema::ExprResult Sema::ActOnPreDefinedExpr(SourceLocation Loc,
     break;
   }
   
-  // Pre-defined identifiers are always of type char *.
-  return new PreDefinedExpr(Loc, Context.getPointerType(Context.CharTy), IT);
+  // Pre-defined identifiers are of type char[x], where x is the length of the
+  // string.
+  llvm::APSInt Length(32);
+  Length = CurFunctionDecl->getIdentifier()->getLength() + 1;
+  QualType ResTy = Context.getConstantArrayType(Context.CharTy, Length,
+                                                ArrayType::Normal, 0);
+  return new PreDefinedExpr(Loc, ResTy, IT);
 }
 
 Sema::ExprResult Sema::ActOnCharacterConstant(const Token &Tok) {
diff --git a/test/Sema/predef.c b/test/Sema/predef.c
new file mode 100644 (file)
index 0000000..f3dae39
--- /dev/null
@@ -0,0 +1,7 @@
+// RUN: clang -fsyntax-only %s
+
+int abcdefghi12(void) {
+ const char (*ss)[12] = &__func__;
+ return sizeof(__func__);
+}
+