[PATCH] D27800: Add overload of TransformToPotentiallyEvaluated for TypeSourceInfo
Paulo Matos via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Tue Jan 11 07:00:12 PST 2022
pmatos updated this revision to Diff 398935.
pmatos added a comment.
Herald added a subscriber: wingo.
Herald added a project: clang.
After a long hiatus on this bug, this is still failing on HEAD so lets get it fixed.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D27800/new/
https://reviews.llvm.org/D27800
Files:
clang/include/clang/Sema/Sema.h
clang/lib/Sema/SemaExpr.cpp
clang/test/SemaCXX/pr31042.cpp
Index: clang/test/SemaCXX/pr31042.cpp
===================================================================
--- /dev/null
+++ clang/test/SemaCXX/pr31042.cpp
@@ -0,0 +1,12 @@
+// RUN: %clang_cc1 -o - -emit-llvm -triple x86_64-unknown-linux-gnu -disable-free %s
+// We need to use -emit-llvm in order to trigger the error, without it semantic analysis
+// does not verify the used bit and there's no error.
+
+char a[1];
+
+void
+f1 (void)
+{
+ int i = 0;
+ int j = sizeof (typeof (*(char (*)[i])a));
+}
Index: clang/lib/Sema/SemaExpr.cpp
===================================================================
--- clang/lib/Sema/SemaExpr.cpp
+++ clang/lib/Sema/SemaExpr.cpp
@@ -4499,6 +4499,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());
}
@@ -16602,6 +16606,16 @@
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: clang/include/clang/Sema/Sema.h
===================================================================
--- clang/include/clang/Sema/Sema.h
+++ clang/include/clang/Sema/Sema.h
@@ -5053,6 +5053,7 @@
void DiscardCleanupsInEvaluationContext();
ExprResult TransformToPotentiallyEvaluated(Expr *E);
+ TypeSourceInfo *TransformToPotentiallyEvaluated(TypeSourceInfo *TInfo);
ExprResult HandleExprEvaluationContextForTypeof(Expr *E);
ExprResult CheckUnevaluatedOperand(Expr *E);
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D27800.398935.patch
Type: text/x-patch
Size: 2095 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220111/c5fc2756/attachment.bin>
More information about the cfe-commits
mailing list