r223266 - Teach EvaluatedExprVisitor that the condition and unselected branches of a

Richard Smith richard-llvm at metafoo.co.uk
Wed Dec 3 13:00:20 PST 2014


Author: rsmith
Date: Wed Dec  3 15:00:20 2014
New Revision: 223266

URL: http://llvm.org/viewvc/llvm-project?rev=223266&view=rev
Log:
Teach EvaluatedExprVisitor that the condition and unselected branches of a
_Generic expression are unevaluated.

Modified:
    cfe/trunk/include/clang/AST/EvaluatedExprVisitor.h
    cfe/trunk/test/Sema/warn-unsequenced.c

Modified: cfe/trunk/include/clang/AST/EvaluatedExprVisitor.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/EvaluatedExprVisitor.h?rev=223266&r1=223265&r2=223266&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/EvaluatedExprVisitor.h (original)
+++ cfe/trunk/include/clang/AST/EvaluatedExprVisitor.h Wed Dec  3 15:00:20 2014
@@ -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.

Modified: cfe/trunk/test/Sema/warn-unsequenced.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/warn-unsequenced.c?rev=223266&r1=223265&r2=223266&view=diff
==============================================================================
--- cfe/trunk/test/Sema/warn-unsequenced.c (original)
+++ cfe/trunk/test/Sema/warn-unsequenced.c Wed Dec  3 15:00:20 2014
@@ -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}}
 }





More information about the cfe-commits mailing list