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
diff --git a/AST/Expr.cpp b/AST/Expr.cpp
index e2f6c62..61b02c3 100644
--- a/AST/Expr.cpp
+++ b/AST/Expr.cpp
@@ -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;
}
}
diff --git a/CodeGen/CGExpr.cpp b/CodeGen/CGExpr.cpp
index 8bc97a9..0fe25c8 100644
--- a/CodeGen/CGExpr.cpp
+++ b/CodeGen/CGExpr.cpp
@@ -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);
}
diff --git a/Sema/SemaExpr.cpp b/Sema/SemaExpr.cpp
index a6808f8..88ee864 100644
--- a/Sema/SemaExpr.cpp
+++ b/Sema/SemaExpr.cpp
@@ -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) {
diff --git a/test/Sema/predef.c b/test/Sema/predef.c
new file mode 100644
index 0000000..f3dae39
--- /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__);
+}
+