From fa28b30d5a1e93e5263be33e343532b900d2c643 Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Sat, 12 Jan 2008 08:14:25 +0000 Subject: [PATCH] Fix the type of predefined identifiers like __func__. Patch by Eli Friedman! git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@45906 91177308-0d34-0410-b5e6-96231b3b80d8 --- AST/Expr.cpp | 4 ++++ CodeGen/CGExpr.cpp | 3 --- Sema/SemaExpr.cpp | 9 +++++++-- test/Sema/predef.c | 7 +++++++ 4 files changed, 18 insertions(+), 5 deletions(-) create mode 100644 test/Sema/predef.c diff --git a/AST/Expr.cpp b/AST/Expr.cpp index e2f6c6210b..61b02c3e71 100644 --- a/AST/Expr.cpp +++ b/AST/Expr.cpp @@ -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(this)->getBase()->hasStaticStorage(); + case PreDefinedExprClass: + return true; } } diff --git a/CodeGen/CGExpr.cpp b/CodeGen/CGExpr.cpp index 8bc97a9d0a..0fe25c8d16 100644 --- a/CodeGen/CGExpr.cpp +++ b/CodeGen/CGExpr.cpp @@ -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); } diff --git a/Sema/SemaExpr.cpp b/Sema/SemaExpr.cpp index a6808f83a7..88ee864b24 100644 --- a/Sema/SemaExpr.cpp +++ b/Sema/SemaExpr.cpp @@ -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 index 0000000000..f3dae39c10 --- /dev/null +++ b/test/Sema/predef.c @@ -0,0 +1,7 @@ +// RUN: clang -fsyntax-only %s + +int abcdefghi12(void) { + const char (*ss)[12] = &__func__; + return sizeof(__func__); +} + -- 2.50.1