Teach EvaluatedExprVisitor that the condition and unselected branches of a

_Generic expression are unevaluated.

llvm-svn: 223266
This commit is contained in:
Richard Smith 2014-12-03 21:00:20 +00:00
parent 5f1529a5ad
commit 1780d82f35
2 changed files with 14 additions and 0 deletions

View File

@ -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.

View File

@ -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}}
}