[PATCH] D27800: Add overload of TransformToPotentiallyEvaluated for TypeSourceInfo

Paulo Matos via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Mar 14 02:01:02 PDT 2017


pmatos updated this revision to Diff 91685.
pmatos added a comment.

Added missing testcase to previous patch.


https://reviews.llvm.org/D27800

Files:
  include/clang/Sema/Sema.h
  lib/Sema/SemaExpr.cpp
  test/SemaCXX/pr31042.cpp


Index: test/SemaCXX/pr31042.cpp
===================================================================
--- test/SemaCXX/pr31042.cpp
+++ test/SemaCXX/pr31042.cpp
@@ -0,0 +1,10 @@
+// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -fsyntax-only -disable-free %s
+
+char a[1];
+
+void
+f1 (void)
+{
+  int i = 0;
+  int j = sizeof (typeof (*(char (*)[i])a));
+}
Index: lib/Sema/SemaExpr.cpp
===================================================================
--- lib/Sema/SemaExpr.cpp
+++ lib/Sema/SemaExpr.cpp
@@ -4024,6 +4024,10 @@
   }
 
   // C99 6.5.3.4p4: the type (an unsigned integer type) is size_t.
+  if (ExprKind == UETT_SizeOf &&
+      TInfo->getType()->isVariablyModifiedType())
+    TInfo = TransformToPotentiallyEvaluated(TInfo);
+  
   return new (Context) UnaryExprOrTypeTraitExpr(
       ExprKind, TInfo, Context.getSizeType(), OpLoc, R.getEnd());
 }
@@ -13111,6 +13115,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
@@ -3791,6 +3791,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.91685.patch
Type: text/x-patch
Size: 1958 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20170314/d6e03307/attachment.bin>


More information about the cfe-commits mailing list