[PATCH] D27800: Add overload of TransformToPotentiallyEvaluated for TypeSourceInfo

Paulo Matos via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Dec 15 01:31:01 PST 2016


pmatos created this revision.
pmatos added a reviewer: efriedma.
pmatos added a subscriber: cfe-commits.

Adds overload of ransformToPotentiallyEvaluated for TypeSourceInfo to properly deal with VLAs in nested calls of sizeof and typeof. Fixes #31042.


https://reviews.llvm.org/D27800

Files:
  include/clang/Sema/Sema.h
  lib/Sema/SemaExpr.cpp


Index: lib/Sema/SemaExpr.cpp
===================================================================
--- lib/Sema/SemaExpr.cpp
+++ lib/Sema/SemaExpr.cpp
@@ -4014,6 +4014,10 @@
   }
 
   // C99 6.5.3.4p4: the type (an unsigned integer type) is size_t.
+  if (isUnevaluatedContext() && ExprKind == UETT_SizeOf &&
+      TInfo->getType()->isVariablyModifiedType())
+    TInfo = TransformToPotentiallyEvaluated(TInfo);
+  
   return new (Context) UnaryExprOrTypeTraitExpr(
       ExprKind, TInfo, Context.getSizeType(), OpLoc, R.getEnd());
 }
@@ -13041,6 +13045,17 @@
   return TransformToPE(*this).TransformExpr(E);
 }
 
+
+TypeSourceInfo *Sema::TransformToPotentiallyEvaluated(TypeSourceInfo *TInfo) {
+  assert(isUnevaluatedContext() &&
+         "Should only transform unevaluated expressions");
+  ExprEvalContexts.back().Context =
+      ExprEvalContexts[ExprEvalContexts.size()-2].Context;
+  if (isUnevaluatedContext())
+    return TInfo;
+  return TransformToPE(*this).TransformType(TInfo);
+}
+
 void
 Sema::PushExpressionEvaluationContext(ExpressionEvaluationContext NewContext,
                                       Decl *LambdaContextDecl,
Index: include/clang/Sema/Sema.h
===================================================================
--- include/clang/Sema/Sema.h
+++ include/clang/Sema/Sema.h
@@ -3720,6 +3720,7 @@
   void DiscardCleanupsInEvaluationContext();
 
   ExprResult TransformToPotentiallyEvaluated(Expr *E);
+  TypeSourceInfo *TransformToPotentiallyEvaluated(TypeSourceInfo *TInfo);
   ExprResult HandleExprEvaluationContextForTypeof(Expr *E);
 
   ExprResult ActOnConstantExpression(ExprResult Res);


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D27800.81547.patch
Type: text/x-patch
Size: 1626 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20161215/8d0eabc2/attachment-0001.bin>


More information about the cfe-commits mailing list