See http://llvm.org/bugs/show_bug.cgi?id=1903. Basic test:
int abcdefghi12(void) {
static const char* s = __func__;
const char (*ss)[12] = &__func__;
return sizeof(__func__);
}
should not give any errors or warnings, and should return 12.
The change in Sema/SemaExpr.cpp is changing the type of __func__ appropriately.
The changes in AST/Expr.cpp makes __func__ be recognized as an lvalue
with static storage duration.
The change in CodeGen/CGExpr.cpp keeps codegen working in the presence
of the new type for __func__.
-Eli
Index: Sema/SemaExpr.cpp
===================================================================
--- Sema/SemaExpr.cpp (revision 45615)
+++ Sema/SemaExpr.cpp (working copy)
@@ -128,8 +129,10 @@
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 = strlen(CurFunctionDecl->getName()) + 1;
+ return new PreDefinedExpr(Loc, Context.getConstantArrayType(Context.CharTy,
length, ArrayType::Normal, 0), IT);
}
Sema::ExprResult Sema::ActOnCharacterConstant(const Token &Tok) {
Index: AST/Expr.cpp
===================================================================
--- AST/Expr.cpp (revision 45615)
+++ AST/Expr.cpp (working copy)
@@ -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 +434,8 @@
}
case ArraySubscriptExprClass:
return cast<ArraySubscriptExpr>(this)->getBase()->hasStaticStorage();
+ case PreDefinedExprClass:
+ return true;
}
}
Index: CodeGen/CGExpr.cpp
===================================================================
--- CodeGen/CGExpr.cpp (revision 45615)
+++ CodeGen/CGExpr.cpp (working copy)
@@ -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);
}
_______________________________________________
cfe-dev mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev