зеркало из https://github.com/microsoft/clang-1.git
Record if a compound literal expression is @ file scope. This allows us to implement C99 6.5.2.5p6. This could have been done without modifying the AST (by checking the decl type and passing the info down to isContextExpr), however we concluded this is more desirable.
Bug/patch by Eli Friedman! git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@45966 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Родитель
5d5480380d
Коммит
e9b12198c4
|
@ -420,6 +420,8 @@ bool Expr::hasStaticStorage() const {
|
|||
return cast<ParenExpr>(this)->getSubExpr()->hasStaticStorage();
|
||||
case ImplicitCastExprClass:
|
||||
return cast<ImplicitCastExpr>(this)->getSubExpr()->hasStaticStorage();
|
||||
case CompoundLiteralExprClass:
|
||||
return cast<CompoundLiteralExpr>(this)->isFileScope();
|
||||
case DeclRefExprClass: {
|
||||
const Decl *D = cast<DeclRefExpr>(this)->getDecl();
|
||||
if (const VarDecl *VD = dyn_cast<VarDecl>(D))
|
||||
|
|
|
@ -392,13 +392,15 @@ void CompoundLiteralExpr::EmitImpl(Serializer& S) const {
|
|||
S.Emit(getType());
|
||||
S.Emit(getLParenLoc());
|
||||
S.EmitOwnedPtr(Init);
|
||||
S.EmitBool(isFileScope());
|
||||
}
|
||||
|
||||
CompoundLiteralExpr* CompoundLiteralExpr::CreateImpl(Deserializer& D) {
|
||||
QualType Q = QualType::ReadVal(D);
|
||||
SourceLocation L = SourceLocation::ReadVal(D);
|
||||
Expr* Init = D.ReadOwnedPtr<Expr>();
|
||||
return new CompoundLiteralExpr(L, Q, Init);
|
||||
bool fileScope = D.ReadBool();
|
||||
return new CompoundLiteralExpr(L, Q, Init, fileScope);
|
||||
}
|
||||
|
||||
void CompoundStmt::EmitImpl(Serializer& S) const {
|
||||
|
|
|
@ -1510,7 +1510,7 @@ Stmt *RewriteTest::RewriteObjCStringLiteral(ObjCStringLiteral *Exp) {
|
|||
InitListExpr *ILE = new InitListExpr(SourceLocation(),
|
||||
&InitExprs[0], InitExprs.size(),
|
||||
SourceLocation());
|
||||
CompoundLiteralExpr *StrRep = new CompoundLiteralExpr(CFConstantStrType, ILE);
|
||||
CompoundLiteralExpr *StrRep = new CompoundLiteralExpr(CFConstantStrType, ILE, false);
|
||||
// struct NSConstantString *
|
||||
expType = Context->getPointerType(StrRep->getType());
|
||||
Unop = new UnaryOperator(StrRep, UnaryOperator::AddrOf, expType,
|
||||
|
@ -1643,7 +1643,7 @@ Stmt *RewriteTest::SynthMessageExpr(ObjCMessageExpr *Exp) {
|
|||
&InitExprs[0], InitExprs.size(),
|
||||
SourceLocation());
|
||||
CompoundLiteralExpr *SuperRep = new CompoundLiteralExpr(SourceLocation(),
|
||||
superType, ILE);
|
||||
superType, ILE, false);
|
||||
// struct objc_super *
|
||||
Expr *Unop = new UnaryOperator(SuperRep, UnaryOperator::AddrOf,
|
||||
Context->getPointerType(SuperRep->getType()),
|
||||
|
@ -1696,7 +1696,7 @@ Stmt *RewriteTest::SynthMessageExpr(ObjCMessageExpr *Exp) {
|
|||
&InitExprs[0], InitExprs.size(),
|
||||
SourceLocation());
|
||||
CompoundLiteralExpr *SuperRep = new CompoundLiteralExpr(SourceLocation(),
|
||||
superType, ILE);
|
||||
superType, ILE, false);
|
||||
// struct objc_super *
|
||||
Expr *Unop = new UnaryOperator(SuperRep, UnaryOperator::AddrOf,
|
||||
Context->getPointerType(SuperRep->getType()),
|
||||
|
|
|
@ -673,12 +673,13 @@ ActOnCompoundLiteral(SourceLocation LParenLoc, TypeTy *Ty,
|
|||
// FIXME: add more semantic analysis (C99 6.5.2.5).
|
||||
if (CheckInitializerTypes(literalExpr, literalType))
|
||||
return true;
|
||||
|
||||
if (!CurFunctionDecl && !CurMethodDecl) { // 6.5.2.5p3
|
||||
|
||||
bool isFileScope = !CurFunctionDecl && !CurMethodDecl;
|
||||
if (isFileScope) { // 6.5.2.5p3
|
||||
if (CheckForConstantInitializer(literalExpr, literalType))
|
||||
return true;
|
||||
}
|
||||
return new CompoundLiteralExpr(LParenLoc, literalType, literalExpr);
|
||||
return new CompoundLiteralExpr(LParenLoc, literalType, literalExpr, isFileScope);
|
||||
}
|
||||
|
||||
Action::ExprResult Sema::
|
||||
|
@ -1963,7 +1964,7 @@ Sema::ExprResult Sema::ActOnBuiltinOffsetOf(SourceLocation BuiltinLoc,
|
|||
|
||||
// Otherwise, create a compound literal expression as the base, and
|
||||
// iteratively process the offsetof designators.
|
||||
Expr *Res = new CompoundLiteralExpr(SourceLocation(), ArgTy, 0);
|
||||
Expr *Res = new CompoundLiteralExpr(SourceLocation(), ArgTy, 0, false);
|
||||
|
||||
// offsetof with non-identifier designators (e.g. "offsetof(x, a.b[c])") are a
|
||||
// GCC extension, diagnose them.
|
||||
|
|
|
@ -728,12 +728,15 @@ class CompoundLiteralExpr : public Expr {
|
|||
/// synthesized compound expression.
|
||||
SourceLocation LParenLoc;
|
||||
Expr *Init;
|
||||
bool FileScope;
|
||||
public:
|
||||
CompoundLiteralExpr(SourceLocation lparenloc, QualType ty, Expr *init) :
|
||||
Expr(CompoundLiteralExprClass, ty), LParenLoc(lparenloc), Init(init) {}
|
||||
CompoundLiteralExpr(SourceLocation lparenloc, QualType ty, Expr *init, bool fileScope) :
|
||||
Expr(CompoundLiteralExprClass, ty), LParenLoc(lparenloc), Init(init), FileScope(fileScope) {}
|
||||
|
||||
const Expr *getInitializer() const { return Init; }
|
||||
Expr *getInitializer() { return Init; }
|
||||
|
||||
bool isFileScope() const { return FileScope; }
|
||||
|
||||
SourceLocation getLParenLoc() const { return LParenLoc; }
|
||||
|
||||
|
|
|
@ -11,6 +11,9 @@ static int x = (int){1}; // -expected-error {{initializer element is not constan
|
|||
static int *p2 = (int []){2,x}; // -expected-error {{initializer element is not constant}}
|
||||
static int *p3 = (int []){2,"x"}; // -expected-warning {{incompatible pointer to integer conversion initializing 'char *', expected 'int'}}
|
||||
|
||||
typedef struct Test {int a;int b;} Test;
|
||||
static Test* ll = &(Test) {0,0};
|
||||
|
||||
extern void fooFunc(struct foo *pfoo);
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
|
|
Загрузка…
Ссылка в новой задаче