Skip to content

Commit 4f07a49

Browse files
Googlercopybara-github
authored andcommitted
Use the initializer Expr that is a child of the constructor now that CXXDefaultInitExprs may be copied in the AST.
This fixes a crash that I believe did not exist before llvm/llvm-project#91879. The CXXDefaultInitExpr that is the in-class member initializer is now not the same object that is referenced through the constructor's initializers, so we could no longer retrieve the correct environment values for the expressions involved. We need to use the object referenced by the constructor's initializers. The minimal crash repro I could find still needed `#include <assert.h>`, so isn't an option for unit tests in collect_evidence_test.cc: ```cpp #include <assert.h> #include <memory> int* g; class C { C() {} std::unique_ptr<int, void (*)(int*)> field_{ g, [](int*) { __assert_fail("", __builtin_FILE(), 0, ""); }}; }; ``` PiperOrigin-RevId: 654006679 Change-Id: If4b8455132ae1b637be3544e15e63bcdf962772b
1 parent f945748 commit 4f07a49

File tree

2 files changed

+9
-8
lines changed

2 files changed

+9
-8
lines changed

bazel/llvm.bzl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ def _llvm_loader_repository(repository_ctx):
5353
executable = False,
5454
)
5555

56-
LLVM_COMMIT_SHA = "5ff3ff33ff930e4ec49da7910612d8a41eb068cb"
56+
LLVM_COMMIT_SHA = "dd7d81ea49bf39e1d69bbb84bd3f31bd95519369"
5757

5858
def llvm_loader_repository_dependencies():
5959
# This *declares* the dependency, but it won't actually be *downloaded* unless it's used.

nullability/inference/collect_evidence.cc

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -433,6 +433,9 @@ static bool isOrIsConstructedFromNullPointerConstant(
433433
Expr::NPCK_NotNull) {
434434
return true;
435435
}
436+
if (auto *DefaultInit = dyn_cast<CXXDefaultInitExpr>(E)) {
437+
E = DefaultInit->getExpr();
438+
}
436439
const Expr *SubExpr = &dataflow::ignoreCFGOmittedNodes(*E);
437440
if (auto *MaterializeTempExpr = dyn_cast<MaterializeTemporaryExpr>(SubExpr)) {
438441
SubExpr = MaterializeTempExpr->getSubExpr();
@@ -1165,14 +1168,11 @@ class DefinitionEvidenceCollector {
11651168
// underlying CXXConstructExpr, so we don't need to handle those, only the
11661169
// member initializers.
11671170
const FieldDecl *Field = Initializer->getAnyMember();
1168-
if (Field == nullptr) return;
1169-
if (InferableSlots.empty()) return;
1170-
bool IsDefaultInitializer = Initializer->isInClassMemberInitializer();
1171-
const Expr *InitExpr = IsDefaultInitializer ? Field->getInClassInitializer()
1172-
: Initializer->getInit();
1173-
1174-
if (!isSupportedPointerType(Field->getType())) return;
1171+
if (Field == nullptr || InferableSlots.empty() ||
1172+
!isSupportedPointerType(Field->getType()))
1173+
return;
11751174

1175+
bool IsDefaultInitializer = Initializer->isInClassMemberInitializer();
11761176
if (isSupportedSmartPointerType(Field->getType()) &&
11771177
!IsDefaultInitializer && !Initializer->isWritten()) {
11781178
// We skip unwritten non-default member initializers for smart pointer
@@ -1183,6 +1183,7 @@ class DefinitionEvidenceCollector {
11831183
return;
11841184
}
11851185

1186+
const Expr *InitExpr = Initializer->getInit();
11861187
bool NullptrDefaultInit =
11871188
IsDefaultInitializer && isOrIsConstructedFromNullPointerConstant(
11881189
InitExpr, Field->getASTContext());

0 commit comments

Comments
 (0)