Fix the type of predefined identifiers like __func__. Patch by

Eli Friedman!

llvm-svn: 45906
This commit is contained in:
Chris Lattner
2008-01-12 08:14:25 +00:00
parent 65531e8fb7
commit a81a0279cc
4 changed files with 18 additions and 5 deletions

View 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;
}
}

View 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);
}

View 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) {

7
clang/test/Sema/predef.c Normal file
View File

@@ -0,0 +1,7 @@
// RUN: clang -fsyntax-only %s
int abcdefghi12(void) {
const char (*ss)[12] = &__func__;
return sizeof(__func__);
}