From 8e531d43500b3de09341c140e48a8059f4acec7a Mon Sep 17 00:00:00 2001 From: Richard Smith Date: Wed, 3 Dec 2014 21:00:20 +0000 Subject: [PATCH] Teach EvaluatedExprVisitor that the condition and unselected branches of a _Generic expression are unevaluated. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@223266 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/AST/EvaluatedExprVisitor.h | 11 +++++++++++ test/Sema/warn-unsequenced.c | 3 +++ 2 files changed, 14 insertions(+) diff --git a/include/clang/AST/EvaluatedExprVisitor.h b/include/clang/AST/EvaluatedExprVisitor.h index 12c4fcc49b..59de104b83 100644 --- a/include/clang/AST/EvaluatedExprVisitor.h +++ b/include/clang/AST/EvaluatedExprVisitor.h @@ -56,6 +56,17 @@ public: return this->Visit(E->getChosenSubExpr()); } + void VisitGenericSelectionExpr(GenericSelectionExpr *E) { + // The controlling expression of a generic selection is not evaluated. + + // Don't visit either child expression if the condition is type-dependent. + if (E->isResultDependent()) + return; + // Only the selected subexpression matters; the other subexpressions and the + // controlling expression are not evaluated. + return this->Visit(E->getResultExpr()); + } + void VisitDesignatedInitExpr(DesignatedInitExpr *E) { // Only the actual initializer matters; the designators are all constant // expressions. diff --git a/test/Sema/warn-unsequenced.c b/test/Sema/warn-unsequenced.c index 10c1ff615c..70163dc0de 100644 --- a/test/Sema/warn-unsequenced.c +++ b/test/Sema/warn-unsequenced.c @@ -90,4 +90,7 @@ void test() { (__builtin_classify_type(++a) ? 1 : 0) + ++a; // ok (__builtin_constant_p(++a) ? 1 : 0) + ++a; // ok (__builtin_expect(++a, 0) ? 1 : 0) + ++a; // expected-warning {{multiple unsequenced modifications}} + _Generic(++a, default: 0) + ++a; // ok + sizeof(++a) + ++a; // ok + _Alignof(++a) + ++a; // expected-warning {{extension}} } -- 2.40.0