diff options
author | Hans Wennborg <hans@hanshq.net> | 2016-02-23 21:20:39 +0000 |
---|---|---|
committer | Hans Wennborg <hans@hanshq.net> | 2016-02-23 21:20:39 +0000 |
commit | 0f8c38be0140104877ce0605c3eafb9c869a641c (patch) | |
tree | 56cc8a9c6b75efbb7a639a526f468969102c705e | |
parent | 797d25cdc4800984005176d8e50e05ef377c20b1 (diff) | |
download | llvm-0f8c38be0140104877ce0605c3eafb9c869a641c.tar.gz |
Merging r261669:llvmorg-3.8.0-rc3
------------------------------------------------------------------------
r261669 | aaronballman | 2016-02-23 10:55:15 -0800 (Tue, 23 Feb 2016) | 1 line
Amends r252104 to evaluate the controlling expression in an unevaluated context. This eliminates false-positive diagnostics about null pointer dereferences (etc) in the controlling expression.
------------------------------------------------------------------------
llvm-svn: 261684
-rw-r--r-- | clang/lib/Sema/SemaExpr.cpp | 11 | ||||
-rw-r--r-- | clang/test/Sema/generic-selection.c | 4 |
2 files changed, 11 insertions, 4 deletions
diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp index ebf79812d8dc..5a2eb6060ee9 100644 --- a/clang/lib/Sema/SemaExpr.cpp +++ b/clang/lib/Sema/SemaExpr.cpp @@ -1365,10 +1365,13 @@ Sema::CreateGenericSelectionExpr(SourceLocation KeyLoc, // Decay and strip qualifiers for the controlling expression type, and handle // placeholder type replacement. See committee discussion from WG14 DR423. - ExprResult R = DefaultFunctionArrayLvalueConversion(ControllingExpr); - if (R.isInvalid()) - return ExprError(); - ControllingExpr = R.get(); + { + EnterExpressionEvaluationContext Unevaluated(*this, Sema::Unevaluated); + ExprResult R = DefaultFunctionArrayLvalueConversion(ControllingExpr); + if (R.isInvalid()) + return ExprError(); + ControllingExpr = R.get(); + } // The controlling expression is an unevaluated operand, so side effects are // likely unintended. diff --git a/clang/test/Sema/generic-selection.c b/clang/test/Sema/generic-selection.c index 0563ec0f4fc0..5c02005d0fa8 100644 --- a/clang/test/Sema/generic-selection.c +++ b/clang/test/Sema/generic-selection.c @@ -31,4 +31,8 @@ void foo(int n) { const int i = 12; int a9[_Generic(i, int: 1, default: 2) == 1 ? 1 : -1]; + + // This is expected to not trigger any diagnostics because the controlling + // expression is not evaluated. + (void)_Generic(*(int *)0, int: 1); } |