[clang] aaae6b1 - Revert "PR44684: Look through parens and similar constructs when determining"
Nico Weber via cfe-commits
cfe-commits at lists.llvm.org
Tue Jan 28 06:04:18 PST 2020
Author: Nico Weber
Date: 2020-01-28T09:03:27-05:00
New Revision: aaae6b1b617378362462c1685e754813ed82b394
URL: https://github.com/llvm/llvm-project/commit/aaae6b1b617378362462c1685e754813ed82b394
DIFF: https://github.com/llvm/llvm-project/commit/aaae6b1b617378362462c1685e754813ed82b394.diff
LOG: Revert "PR44684: Look through parens and similar constructs when determining"
This reverts commit af80b8ccc5772c14920d4554b7ca7e15f2fad1c4.
It broke clang-tidy/checkers/modernize-use-uncaught-exceptions.cpp in
check-clang-tools on macOS and Windows, see e.g.
http://lab.llvm.org:8011/builders/clang-x64-windows-msvc/builds/13976/steps/stage%201%20check/logs/stdio
Added:
Modified:
clang/lib/AST/Expr.cpp
clang/lib/AST/ExprConstant.cpp
clang/test/Parser/builtin_classify_type.c
clang/test/Sema/constant-builtins.c
Removed:
################################################################################
diff --git a/clang/lib/AST/Expr.cpp b/clang/lib/AST/Expr.cpp
index c2f73c2dc9d5..20505b21b15c 100644
--- a/clang/lib/AST/Expr.cpp
+++ b/clang/lib/AST/Expr.cpp
@@ -1443,28 +1443,19 @@ void CallExpr::updateDependenciesFromArg(Expr *Arg) {
Decl *Expr::getReferencedDeclOfCallee() {
Expr *CEE = IgnoreParenImpCasts();
- while (SubstNonTypeTemplateParmExpr *NTTP =
- dyn_cast<SubstNonTypeTemplateParmExpr>(CEE)) {
- CEE = NTTP->getReplacement()->IgnoreParenImpCasts();
+ while (SubstNonTypeTemplateParmExpr *NTTP
+ = dyn_cast<SubstNonTypeTemplateParmExpr>(CEE)) {
+ CEE = NTTP->getReplacement()->IgnoreParenCasts();
}
// If we're calling a dereference, look at the pointer instead.
- while (true) {
- if (BinaryOperator *BO = dyn_cast<BinaryOperator>(CEE)) {
- if (BO->isPtrMemOp()) {
- CEE = BO->getRHS()->IgnoreParenImpCasts();
- continue;
- }
- } else if (UnaryOperator *UO = dyn_cast<UnaryOperator>(CEE)) {
- if (UO->getOpcode() == UO_Deref || UO->getOpcode() == UO_AddrOf ||
- UO->getOpcode() == UO_Plus) {
- CEE = UO->getSubExpr()->IgnoreParenImpCasts();
- continue;
- }
- }
- break;
+ if (BinaryOperator *BO = dyn_cast<BinaryOperator>(CEE)) {
+ if (BO->isPtrMemOp())
+ CEE = BO->getRHS()->IgnoreParenCasts();
+ } else if (UnaryOperator *UO = dyn_cast<UnaryOperator>(CEE)) {
+ if (UO->getOpcode() == UO_Deref)
+ CEE = UO->getSubExpr()->IgnoreParenCasts();
}
-
if (DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(CEE))
return DRE->getDecl();
if (MemberExpr *ME = dyn_cast<MemberExpr>(CEE))
@@ -1475,11 +1466,28 @@ Decl *Expr::getReferencedDeclOfCallee() {
return nullptr;
}
-/// If this is a call to a builtin, return the builtin ID. If not, return 0.
+/// getBuiltinCallee - If this is a call to a builtin, return the builtin ID. If
+/// not, return 0.
unsigned CallExpr::getBuiltinCallee() const {
- auto *FDecl =
- dyn_cast_or_null<FunctionDecl>(getCallee()->getReferencedDeclOfCallee());
- return FDecl ? FDecl->getBuiltinID() : 0;
+ // All simple function calls (e.g. func()) are implicitly cast to pointer to
+ // function. As a result, we try and obtain the DeclRefExpr from the
+ // ImplicitCastExpr.
+ const ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(getCallee());
+ if (!ICE) // FIXME: deal with more complex calls (e.g. (func)(), (*func)()).
+ return 0;
+
+ const DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(ICE->getSubExpr());
+ if (!DRE)
+ return 0;
+
+ const FunctionDecl *FDecl = dyn_cast<FunctionDecl>(DRE->getDecl());
+ if (!FDecl)
+ return 0;
+
+ if (!FDecl->getIdentifier())
+ return 0;
+
+ return FDecl->getBuiltinID();
}
bool CallExpr::isUnevaluatedBuiltinCall(const ASTContext &Ctx) const {
diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
index 75554c4692e9..c79973507323 100644
--- a/clang/lib/AST/ExprConstant.cpp
+++ b/clang/lib/AST/ExprConstant.cpp
@@ -10660,7 +10660,7 @@ static bool getBuiltinAlignArguments(const CallExpr *E, EvalInfo &Info,
bool IntExprEvaluator::VisitBuiltinCallExpr(const CallExpr *E,
unsigned BuiltinOp) {
- switch (BuiltinOp) {
+ switch (unsigned BuiltinOp = E->getBuiltinCallee()) {
default:
return ExprEvaluatorBaseTy::VisitCallExpr(E);
diff --git a/clang/test/Parser/builtin_classify_type.c b/clang/test/Parser/builtin_classify_type.c
index 94434e9f2ee4..63fd8e28045a 100644
--- a/clang/test/Parser/builtin_classify_type.c
+++ b/clang/test/Parser/builtin_classify_type.c
@@ -9,7 +9,7 @@ int main() {
struct foo s;
static int ary[__builtin_classify_type(a)];
- static int ary2[(__builtin_classify_type)(a)];
+ static int ary2[(__builtin_classify_type)(a)]; // expected-error{{variable length array declaration cannot have 'static' storage duration}}
static int ary3[(*__builtin_classify_type)(a)]; // expected-error{{builtin functions must be directly called}}
int result;
diff --git a/clang/test/Sema/constant-builtins.c b/clang/test/Sema/constant-builtins.c
index ae3b9135c965..c98f62dfc5a2 100644
--- a/clang/test/Sema/constant-builtins.c
+++ b/clang/test/Sema/constant-builtins.c
@@ -25,13 +25,4 @@ short somefunc();
short t = __builtin_constant_p(5353) ? 42 : somefunc();
-// PR44684
-_Static_assert((__builtin_clz)(1u) >= 15, "");
-_Static_assert((__builtin_popcount)(1u) == 1, "");
-_Static_assert((__builtin_ctz)(2u) == 1, "");
-_Static_assert(_Generic(1u,unsigned:__builtin_clz)(1u) >= 15, "");
-_Static_assert(_Generic(1u,unsigned:__builtin_popcount)(1u) == 1, "");
-_Static_assert(_Generic(1u,unsigned:__builtin_ctz)(2u) == 1, "");
-
-__SIZE_TYPE__ strlen(const char*);
-_Static_assert((__builtin_constant_p(1) ? (***&strlen)("foo") : 0) == 3, "");
+
More information about the cfe-commits
mailing list