[PATCH] D22419: [CFG] Fix crash in thread sanitizer.
Nandor Licker via cfe-commits
cfe-commits at lists.llvm.org
Mon Jul 18 13:09:03 PDT 2016
nandor updated this revision to Diff 64368.
nandor added a comment.
Fixed typo
https://reviews.llvm.org/D22419
Files:
lib/Analysis/CFG.cpp
test/SemaCXX/warn-thread-safety-analysis.cpp
Index: test/SemaCXX/warn-thread-safety-analysis.cpp
===================================================================
--- test/SemaCXX/warn-thread-safety-analysis.cpp
+++ test/SemaCXX/warn-thread-safety-analysis.cpp
@@ -5160,6 +5160,21 @@
} // end namespace GlobalAcquiredBeforeAfterTest
+namespace LifetimeExtensionTest {
+
+struct Holder {
+ virtual ~Holder() throw() {}
+ int i = 0;
+};
+
+void test() {
+ // Should not crash.
+ const auto &value = Holder().i;
+}
+
+} // end namespace LifetimeExtensionTest
+
+
namespace LockableUnions {
union LOCKABLE MutexUnion {
Index: lib/Analysis/CFG.cpp
===================================================================
--- lib/Analysis/CFG.cpp
+++ lib/Analysis/CFG.cpp
@@ -3902,7 +3902,20 @@
case CFGElement::AutomaticObjectDtor: {
const VarDecl *var = castAs<CFGAutomaticObjDtor>().getVarDecl();
QualType ty = var->getType();
- ty = ty.getNonReferenceType();
+
+ // FIXME: See CFGBuilder::addLocalScopeForVarDecl.
+ //
+ // Lifetime-extending constructs are handled here. This works for a single
+ // temporary in an initializer expression.
+ if (ty.getTypePtr()->isReferenceType()) {
+ if (const Expr *Init = var->getInit()) {
+ if (const ExprWithCleanups *EWC = dyn_cast<ExprWithCleanups>(Init))
+ Init = EWC->getSubExpr();
+ if (isa<MaterializeTemporaryExpr>(Init))
+ ty = getReferenceInitTemporaryType(astContext, Init);
+ }
+ }
+
while (const ArrayType *arrayType = astContext.getAsArrayType(ty)) {
ty = arrayType->getElementType();
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D22419.64368.patch
Type: text/x-patch
Size: 1636 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20160718/879e64a1/attachment.bin>
More information about the cfe-commits
mailing list