From b9eb35ced8369c8c8479efc17712faaf34e16c56 Mon Sep 17 00:00:00 2001 From: Abramo Bagnara Date: Fri, 15 Oct 2010 07:51:18 +0000 Subject: [PATCH] Treat __extension__ like ParenExpr. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@116569 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/AST/Expr.cpp | 62 ++++++++++++++++++++++++++++++--------- test/Parser/expressions.c | 3 +- 2 files changed, 50 insertions(+), 15 deletions(-) diff --git a/lib/AST/Expr.cpp b/lib/AST/Expr.cpp index 98f0656ad1..92e7119445 100644 --- a/lib/AST/Expr.cpp +++ b/lib/AST/Expr.cpp @@ -1554,10 +1554,19 @@ Expr::CanThrowResult Expr::CanThrow(ASTContext &C) const { Expr* Expr::IgnoreParens() { Expr* E = this; - while (ParenExpr* P = dyn_cast(E)) - E = P->getSubExpr(); - - return E; + while (true) { + if (ParenExpr* P = dyn_cast(E)) { + E = P->getSubExpr(); + continue; + } + if (UnaryOperator* P = dyn_cast(E)) { + if (P->getOpcode() == UO_Extension) { + E = P->getSubExpr(); + continue; + } + } + return E; + } } /// IgnoreParenCasts - Ignore parentheses and casts. Strip off any ParenExpr @@ -1565,24 +1574,42 @@ Expr* Expr::IgnoreParens() { Expr *Expr::IgnoreParenCasts() { Expr *E = this; while (true) { - if (ParenExpr *P = dyn_cast(E)) + if (ParenExpr* P = dyn_cast(E)) { E = P->getSubExpr(); - else if (CastExpr *P = dyn_cast(E)) + continue; + } + if (CastExpr *P = dyn_cast(E)) { E = P->getSubExpr(); - else - return E; + continue; + } + if (UnaryOperator* P = dyn_cast(E)) { + if (P->getOpcode() == UO_Extension) { + E = P->getSubExpr(); + continue; + } + } + return E; } } Expr *Expr::IgnoreParenImpCasts() { Expr *E = this; while (true) { - if (ParenExpr *P = dyn_cast(E)) + if (ParenExpr *P = dyn_cast(E)) { E = P->getSubExpr(); - else if (ImplicitCastExpr *P = dyn_cast(E)) + continue; + } + if (ImplicitCastExpr *P = dyn_cast(E)) { E = P->getSubExpr(); - else - return E; + continue; + } + if (UnaryOperator* P = dyn_cast(E)) { + if (P->getOpcode() == UO_Extension) { + E = P->getSubExpr(); + continue; + } + } + return E; } } @@ -1607,9 +1634,9 @@ Expr *Expr::IgnoreParenNoopCasts(ASTContext &Ctx) { continue; } - if ((E->getType()->isPointerType() || + if ((E->getType()->isPointerType() || E->getType()->isIntegralType(Ctx)) && - (SE->getType()->isPointerType() || + (SE->getType()->isPointerType() || SE->getType()->isIntegralType(Ctx)) && Ctx.getTypeSize(E->getType()) == Ctx.getTypeSize(SE->getType())) { E = SE; @@ -1617,6 +1644,13 @@ Expr *Expr::IgnoreParenNoopCasts(ASTContext &Ctx) { } } + if (UnaryOperator* P = dyn_cast(E)) { + if (P->getOpcode() == UO_Extension) { + E = P->getSubExpr(); + continue; + } + } + return E; } } diff --git a/test/Parser/expressions.c b/test/Parser/expressions.c index ffc5c83a0a..6015e918a3 100644 --- a/test/Parser/expressions.c +++ b/test/Parser/expressions.c @@ -39,7 +39,8 @@ void test_sizeof(){ // PR3418 int test_leading_extension() { - __extension__ (*(char*)0) = 1; + __extension__ (*(char*)0) = 1; // expected-warning {{indirection of non-volatile null pointer}} \ + // expected-note {{consider using __builtin_trap}} return 0; } -- 2.40.0