[PATCH] D17507: The controlling expression for _Generic is unevaluated

Aaron Ballman via cfe-commits cfe-commits at lists.llvm.org
Mon Feb 22 07:52:15 PST 2016


aaron.ballman created this revision.
aaron.ballman added a reviewer: rsmith.
aaron.ballman added a subscriber: cfe-commits.

In r252104, I fixed a _Generic bug so that the controlling expression has its type decayed and qualifiers stripped. However, this caused a diagnostic regression because the controlling expression is not evaluated, and my fix triggered diagnostics (like null pointer dereferences) that it should not have. This patch fixes the regression by putting the evaluation of the controlling expression into an unevaluated context before decaying and stripping qualifiers.

Assuming this patch is acceptable, I think it should go into 3.8 as well.

http://reviews.llvm.org/D17507

Files:
  lib/Sema/SemaExpr.cpp
  test/Sema/generic-selection.c

Index: test/Sema/generic-selection.c
===================================================================
--- test/Sema/generic-selection.c
+++ test/Sema/generic-selection.c
@@ -31,4 +31,8 @@
 
   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);
 }
Index: lib/Sema/SemaExpr.cpp
===================================================================
--- lib/Sema/SemaExpr.cpp
+++ lib/Sema/SemaExpr.cpp
@@ -1373,10 +1373,13 @@
 
   // 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.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D17507.48679.patch
Type: text/x-patch
Size: 1264 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20160222/0abab518/attachment.bin>


More information about the cfe-commits mailing list