[cfe-commits] r45906 - in /cfe/trunk: AST/Expr.cpp CodeGen/CGExpr.cpp Sema/SemaExpr.cpp test/Sema/predef.c
Chris Lattner
sabre at nondot.org
Sat Jan 12 00:14:26 PST 2008
Author: lattner
Date: Sat Jan 12 02:14:25 2008
New Revision: 45906
URL: http://llvm.org/viewvc/llvm-project?rev=45906&view=rev
Log:
Fix the type of predefined identifiers like __func__. Patch by
Eli Friedman!
Added:
cfe/trunk/test/Sema/predef.c
Modified:
cfe/trunk/AST/Expr.cpp
cfe/trunk/CodeGen/CGExpr.cpp
cfe/trunk/Sema/SemaExpr.cpp
Modified: cfe/trunk/AST/Expr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/AST/Expr.cpp?rev=45906&r1=45905&r2=45906&view=diff
==============================================================================
--- cfe/trunk/AST/Expr.cpp (original)
+++ cfe/trunk/AST/Expr.cpp Sat Jan 12 02:14:25 2008
@@ -372,6 +372,8 @@
return LV_Valid;
case ObjCIvarRefExprClass: // ObjC instance variables are lvalues.
return LV_Valid;
+ case PreDefinedExprClass:
+ return LV_Valid;
default:
break;
}
@@ -430,6 +432,8 @@
}
case ArraySubscriptExprClass:
return cast<ArraySubscriptExpr>(this)->getBase()->hasStaticStorage();
+ case PreDefinedExprClass:
+ return true;
}
}
Modified: cfe/trunk/CodeGen/CGExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/CodeGen/CGExpr.cpp?rev=45906&r1=45905&r2=45906&view=diff
==============================================================================
--- cfe/trunk/CodeGen/CGExpr.cpp (original)
+++ cfe/trunk/CodeGen/CGExpr.cpp Sat Jan 12 02:14:25 2008
@@ -340,9 +340,6 @@
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);
}
Modified: cfe/trunk/Sema/SemaExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Sema/SemaExpr.cpp?rev=45906&r1=45905&r2=45906&view=diff
==============================================================================
--- cfe/trunk/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/Sema/SemaExpr.cpp Sat Jan 12 02:14:25 2008
@@ -128,8 +128,13 @@
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) {
Added: cfe/trunk/test/Sema/predef.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/predef.c?rev=45906&view=auto
==============================================================================
--- cfe/trunk/test/Sema/predef.c (added)
+++ cfe/trunk/test/Sema/predef.c Sat Jan 12 02:14:25 2008
@@ -0,0 +1,7 @@
+// RUN: clang -fsyntax-only %s
+
+int abcdefghi12(void) {
+ const char (*ss)[12] = &__func__;
+ return sizeof(__func__);
+}
+
More information about the cfe-commits
mailing list