[PATCH] D108482: [Clang] Fixes instantiation of OpaqueValueExprs (Bug #45964)
Jason Rice via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Fri Aug 20 14:53:10 PDT 2021
ricejasonf updated this revision to Diff 367907.
ricejasonf added a comment.
Fixed the formatting with clang-format
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D108482/new/
https://reviews.llvm.org/D108482
Files:
clang/lib/Sema/SemaInit.cpp
clang/lib/Sema/TreeTransform.h
Index: clang/lib/Sema/TreeTransform.h
===================================================================
--- clang/lib/Sema/TreeTransform.h
+++ clang/lib/Sema/TreeTransform.h
@@ -10511,7 +10511,19 @@
TreeTransform<Derived>::TransformOpaqueValueExpr(OpaqueValueExpr *E) {
assert((!E->getSourceExpr() || getDerived().AlreadyTransformed(E->getType())) &&
"opaque value expression requires transformation");
- return E;
+
+ // Note that SourceExpr can be nullptr
+ ExprResult SourceExpr = TransformExpr(E->getSourceExpr());
+ if (SourceExpr.isInvalid())
+ return ExprError();
+ if (SourceExpr.get() == E->getSourceExpr() && !getDerived().AlwaysRebuild()) {
+ return E;
+ }
+
+ OpaqueValueExpr *New = new (SemaRef.Context)
+ OpaqueValueExpr(E->getExprLoc(), E->getType(), E->getValueKind(),
+ E->getObjectKind(), SourceExpr.get());
+ return New;
}
template<typename Derived>
Index: clang/lib/Sema/SemaInit.cpp
===================================================================
--- clang/lib/Sema/SemaInit.cpp
+++ clang/lib/Sema/SemaInit.cpp
@@ -8643,9 +8643,13 @@
case SK_ArrayLoopIndex: {
Expr *Cur = CurInit.get();
- Expr *BaseExpr = new (S.Context)
- OpaqueValueExpr(Cur->getExprLoc(), Cur->getType(),
- Cur->getValueKind(), Cur->getObjectKind(), Cur);
+ // prevent nested OpaqueValueExprs
+ Expr *BaseExpr = dyn_cast<OpaqueValueExpr>(Cur);
+ if (!BaseExpr) {
+ BaseExpr = new (S.Context)
+ OpaqueValueExpr(Cur->getExprLoc(), Cur->getType(),
+ Cur->getValueKind(), Cur->getObjectKind(), Cur);
+ }
Expr *IndexExpr =
new (S.Context) ArrayInitIndexExpr(S.Context.getSizeType());
CurInit = S.CreateBuiltinArraySubscriptExpr(
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D108482.367907.patch
Type: text/x-patch
Size: 1822 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20210820/9e4491ee/attachment.bin>
More information about the cfe-commits
mailing list