Skip to content

[analyzer] Make it a noop when initializing a field of empty record #138594

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
May 7, 2025

Conversation

ziqingluo-90
Copy link
Contributor

Previously, Static Analyzer initializes empty type fields with zeroes. This can cause problems when those fields have no unique addresses. For example, #137252.

rdar://146753089

…cord.

Previously, Static Analyzer initializes empty type fields with zeroes.
This can cause problems when those fields have no unique addresses.
For example, llvm#137252.

rdar://146753089
@ziqingluo-90 ziqingluo-90 requested a review from steakhal May 5, 2025 21:40
@llvmbot llvmbot added clang Clang issues not falling into any other category clang:static analyzer labels May 5, 2025
@llvmbot
Copy link
Member

llvmbot commented May 5, 2025

@llvm/pr-subscribers-clang

@llvm/pr-subscribers-clang-static-analyzer-1

Author: Ziqing Luo (ziqingluo-90)

Changes

Previously, Static Analyzer initializes empty type fields with zeroes. This can cause problems when those fields have no unique addresses. For example, #137252.

rdar://146753089


Full diff: https://github.com/llvm/llvm-project/pull/138594.diff

2 Files Affected:

  • (modified) clang/lib/StaticAnalyzer/Core/ExprEngineCXX.cpp (+7-1)
  • (added) clang/test/Analysis/issue-137252.cpp (+45)
diff --git a/clang/lib/StaticAnalyzer/Core/ExprEngineCXX.cpp b/clang/lib/StaticAnalyzer/Core/ExprEngineCXX.cpp
index 92ce3fa2225c8..219d7b4d2278c 100644
--- a/clang/lib/StaticAnalyzer/Core/ExprEngineCXX.cpp
+++ b/clang/lib/StaticAnalyzer/Core/ExprEngineCXX.cpp
@@ -10,6 +10,7 @@
 //
 //===----------------------------------------------------------------------===//
 
+#include "clang/AST/ASTContext.h"
 #include "clang/AST/AttrIterator.h"
 #include "clang/AST/DeclCXX.h"
 #include "clang/AST/ParentMap.h"
@@ -700,6 +701,7 @@ void ExprEngine::handleConstructor(const Expr *E,
   if (CE) {
     // FIXME: Is it possible and/or useful to do this before PreStmt?
     StmtNodeBuilder Bldr(DstPreVisit, PreInitialized, *currBldrCtx);
+    ASTContext &Ctx = LCtx->getAnalysisDeclContext()->getASTContext();
     for (ExplodedNode *N : DstPreVisit) {
       ProgramStateRef State = N->getState();
       if (CE->requiresZeroInitialization()) {
@@ -715,7 +717,11 @@ void ExprEngine::handleConstructor(const Expr *E,
         // actually make things worse. Placement new makes this tricky as well,
         // since it's then possible to be initializing one part of a multi-
         // dimensional array.
-        State = State->bindDefaultZero(Target, LCtx);
+        const CXXRecordDecl *TargetHeldRecord =
+            Target.getType(Ctx)->getPointeeCXXRecordDecl();
+
+        if (!TargetHeldRecord || !TargetHeldRecord->isEmpty())
+          State = State->bindDefaultZero(Target, LCtx);
       }
 
       Bldr.generateNode(CE, N, State, /*tag=*/nullptr,
diff --git a/clang/test/Analysis/issue-137252.cpp b/clang/test/Analysis/issue-137252.cpp
new file mode 100644
index 0000000000000..8064e3f54d9fd
--- /dev/null
+++ b/clang/test/Analysis/issue-137252.cpp
@@ -0,0 +1,45 @@
+// RUN: %clang_analyze_cc1 -analyzer-checker=cplusplus -verify %s
+// RUN: %clang_analyze_cc1 -analyzer-checker=cplusplus -verify %s -DEMPTY_CLASS
+
+// expected-no-diagnostics
+
+// This test reproduces the issue that previously the static analyzer
+// initialized an [[__no_unique_address__]] empty field to zero,
+// over-writing a non-empty field with the same offset.
+
+namespace std {
+#ifdef EMPTY_CLASS
+
+  template <typename T>
+  class default_delete {
+    T dump();
+    static T x;
+  };
+  template <class _Tp, class _Dp = default_delete<_Tp> >
+#else
+
+  struct default_delete {};
+  template <class _Tp, class _Dp = default_delete >
+#endif
+  class unique_ptr {
+    [[__no_unique_address__]]  _Tp * __ptr_;
+    [[__no_unique_address__]] _Dp __deleter_;
+
+  public:
+    explicit unique_ptr(_Tp* __p) noexcept
+      : __ptr_(__p),
+        __deleter_() {}
+
+    ~unique_ptr() {
+      delete __ptr_;
+    }
+  };
+}
+
+struct X {};
+
+int main()
+{
+    std::unique_ptr<X> a(new X());          // previously leak falsely reported
+    return 0;
+}

@ziqingluo-90
Copy link
Contributor Author

CC: @dtarditi

Copy link
Member

@isuckatcs isuckatcs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Contributor

@steakhal steakhal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for your contribution, and debugging the case.
Left a couple of comments inline.

@dtarditi
Copy link
Contributor

dtarditi commented May 7, 2025

LGTM. @ziqingluo-90 thank you for fixing this problem!

@steakhal steakhal changed the title [StaticAnalyzer] Make it a noop when initializing a field of empty record [analyzer] Make it a noop when initializing a field of empty record May 7, 2025
Copy link
Contributor

@steakhal steakhal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed, it looks great now. Thank you!
Let's merge this.

@steakhal steakhal merged commit db38cc2 into llvm:main May 7, 2025
6 of 9 checks passed
@llvm-ci
Copy link
Collaborator

llvm-ci commented May 7, 2025

LLVM Buildbot has detected a new failure on builder llvm-clang-x86_64-sie-ubuntu-fast running on sie-linux-worker while building clang at step 6 "test-build-unified-tree-check-all".

Full details are available at: https://lab.llvm.org/buildbot/#/builders/144/builds/24534

Here is the relevant piece of the build log for the reference
Step 6 (test-build-unified-tree-check-all) failure: test (failure)
******************** TEST 'Clang :: Analysis/ctor.mm' FAILED ********************
Exit Code: 134

Command Output (stderr):
--
/home/buildbot/buildbot-root/llvm-clang-x86_64-sie-ubuntu-fast/build/bin/clang -cc1 -internal-isystem /home/buildbot/buildbot-root/llvm-clang-x86_64-sie-ubuntu-fast/build/lib/clang/21/include -nostdsysteminc -analyze -analyzer-constraints=range -setup-static-analyzer -triple i386-apple-darwin10 -DI386 -analyzer-checker=core,debug.ExprInspection -fobjc-arc -analyzer-config c++-inlining=constructors -Wno-null-dereference -std=c++11 -verify -analyzer-config eagerly-assume=false /home/buildbot/buildbot-root/llvm-clang-x86_64-sie-ubuntu-fast/llvm-project/clang/test/Analysis/ctor.mm # RUN: at line 1
+ /home/buildbot/buildbot-root/llvm-clang-x86_64-sie-ubuntu-fast/build/bin/clang -cc1 -internal-isystem /home/buildbot/buildbot-root/llvm-clang-x86_64-sie-ubuntu-fast/build/lib/clang/21/include -nostdsysteminc -analyze -analyzer-constraints=range -setup-static-analyzer -triple i386-apple-darwin10 -DI386 -analyzer-checker=core,debug.ExprInspection -fobjc-arc -analyzer-config c++-inlining=constructors -Wno-null-dereference -std=c++11 -verify -analyzer-config eagerly-assume=false /home/buildbot/buildbot-root/llvm-clang-x86_64-sie-ubuntu-fast/llvm-project/clang/test/Analysis/ctor.mm
clang: /home/buildbot/buildbot-root/llvm-clang-x86_64-sie-ubuntu-fast/llvm-project/llvm/include/llvm/Support/Casting.h:109: static bool llvm::isa_impl_cl<To, const From*>::doit(const From*) [with To = clang::CXXRecordDecl; From = clang::RecordDecl]: Assertion `Val && "isa<> used on a null pointer"' failed.
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace, preprocessed source, and associated run script.
Stack dump:
0.	Program arguments: /home/buildbot/buildbot-root/llvm-clang-x86_64-sie-ubuntu-fast/build/bin/clang -cc1 -internal-isystem /home/buildbot/buildbot-root/llvm-clang-x86_64-sie-ubuntu-fast/build/lib/clang/21/include -nostdsysteminc -analyze -analyzer-constraints=range -setup-static-analyzer -triple i386-apple-darwin10 -DI386 -analyzer-checker=core,debug.ExprInspection -fobjc-arc -analyzer-config c++-inlining=constructors -Wno-null-dereference -std=c++11 -verify -analyzer-config eagerly-assume=false /home/buildbot/buildbot-root/llvm-clang-x86_64-sie-ubuntu-fast/llvm-project/clang/test/Analysis/ctor.mm
1.	<eof> parser at end of file
2.	While analyzing stack: 
	#0 Calling ZeroInitialization::testArrayNew()
3.	/home/buildbot/buildbot-root/llvm-clang-x86_64-sie-ubuntu-fast/llvm-project/clang/test/Analysis/ctor.mm:580:23: Error evaluating statement
4.	/home/buildbot/buildbot-root/llvm-clang-x86_64-sie-ubuntu-fast/llvm-project/clang/test/Analysis/ctor.mm:580:23: Error evaluating statement
 #0 0x00005e08acacb8c0 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/home/buildbot/buildbot-root/llvm-clang-x86_64-sie-ubuntu-fast/build/bin/clang+0x22148c0)
 #1 0x00005e08acac8ccf llvm::sys::RunSignalHandlers() (/home/buildbot/buildbot-root/llvm-clang-x86_64-sie-ubuntu-fast/build/bin/clang+0x2211ccf)
 #2 0x00005e08acac8e1a SignalHandler(int, siginfo_t*, void*) Signals.cpp:0:0
 #3 0x000077990d796520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)
 #4 0x000077990d7ea9fc __pthread_kill_implementation ./nptl/pthread_kill.c:44:76
 #5 0x000077990d7ea9fc __pthread_kill_internal ./nptl/pthread_kill.c:78:10
 #6 0x000077990d7ea9fc pthread_kill ./nptl/pthread_kill.c:89:10
 #7 0x000077990d796476 gsignal ./signal/../sysdeps/posix/raise.c:27:6
 #8 0x000077990d77c7f3 abort ./stdlib/abort.c:81:7
 #9 0x000077990d77c71b _nl_load_domain ./intl/loadmsgcat.c:1177:9
#10 0x000077990d78de96 (/lib/x86_64-linux-gnu/libc.so.6+0x39e96)
#11 0x00005e08aee22a7c clang::ento::ExprEngine::handleConstructor(clang::Expr const*, clang::ento::ExplodedNode*, clang::ento::ExplodedNodeSet&) (/home/buildbot/buildbot-root/llvm-clang-x86_64-sie-ubuntu-fast/build/bin/clang+0x456ba7c)
#12 0x00005e08aee00f9c clang::ento::ExprEngine::Visit(clang::Stmt const*, clang::ento::ExplodedNode*, clang::ento::ExplodedNodeSet&) (/home/buildbot/buildbot-root/llvm-clang-x86_64-sie-ubuntu-fast/build/bin/clang+0x4549f9c)
#13 0x00005e08aee02e2f clang::ento::ExprEngine::ProcessStmt(clang::Stmt const*, clang::ento::ExplodedNode*) (/home/buildbot/buildbot-root/llvm-clang-x86_64-sie-ubuntu-fast/build/bin/clang+0x454be2f)
#14 0x00005e08aee0a8ec clang::ento::ExprEngine::processCFGElement(clang::CFGElement, clang::ento::ExplodedNode*, unsigned int, clang::ento::NodeBuilderContext*) (/home/buildbot/buildbot-root/llvm-clang-x86_64-sie-ubuntu-fast/build/bin/clang+0x45538ec)
#15 0x00005e08aedb90e6 clang::ento::CoreEngine::HandlePostStmt(clang::CFGBlock const*, unsigned int, clang::ento::ExplodedNode*) (/home/buildbot/buildbot-root/llvm-clang-x86_64-sie-ubuntu-fast/build/bin/clang+0x45020e6)
#16 0x00005e08aedb97de clang::ento::CoreEngine::dispatchWorkItem(clang::ento::ExplodedNode*, clang::ProgramPoint, clang::ento::WorkListUnit const&) (/home/buildbot/buildbot-root/llvm-clang-x86_64-sie-ubuntu-fast/build/bin/clang+0x45027de)
#17 0x00005e08aedb9961 clang::ento::CoreEngine::ExecuteWorkList(clang::LocationContext const*, unsigned int, llvm::IntrusiveRefCntPtr<clang::ento::ProgramState const>) (/home/buildbot/buildbot-root/llvm-clang-x86_64-sie-ubuntu-fast/build/bin/clang+0x4502961)
#18 0x00005e08ae973879 (anonymous namespace)::AnalysisConsumer::HandleCode(clang::Decl*, unsigned int, clang::ento::ExprEngine::InliningModes, llvm::DenseSet<clang::Decl const*, llvm::DenseMapInfo<clang::Decl const*, void>>*) AnalysisConsumer.cpp:0:0
#19 0x00005e08ae975658 (anonymous namespace)::AnalysisConsumer::HandleDeclsCallGraph(unsigned int) AnalysisConsumer.cpp:0:0
#20 0x00005e08ae97702b (anonymous namespace)::AnalysisConsumer::HandleTranslationUnit(clang::ASTContext&) AnalysisConsumer.cpp:0:0
#21 0x00005e08aef3fd1c clang::ParseAST(clang::Sema&, bool, bool) (/home/buildbot/buildbot-root/llvm-clang-x86_64-sie-ubuntu-fast/build/bin/clang+0x4688d1c)
#22 0x00005e08ad768ea9 clang::FrontendAction::Execute() (/home/buildbot/buildbot-root/llvm-clang-x86_64-sie-ubuntu-fast/build/bin/clang+0x2eb1ea9)
#23 0x00005e08ad6e3885 clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/home/buildbot/buildbot-root/llvm-clang-x86_64-sie-ubuntu-fast/build/bin/clang+0x2e2c885)
#24 0x00005e08ad856048 clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/home/buildbot/buildbot-root/llvm-clang-x86_64-sie-ubuntu-fast/build/bin/clang+0x2f9f048)
#25 0x00005e08ab58346b cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/home/buildbot/buildbot-root/llvm-clang-x86_64-sie-ubuntu-fast/build/bin/clang+0xccc46b)
#26 0x00005e08ab57896a ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&, llvm::ToolContext const&) driver.cpp:0:0
#27 0x00005e08ab57d64e clang_main(int, char**, llvm::ToolContext const&) (/home/buildbot/buildbot-root/llvm-clang-x86_64-sie-ubuntu-fast/build/bin/clang+0xcc664e)
#28 0x00005e08ab466a4b main (/home/buildbot/buildbot-root/llvm-clang-x86_64-sie-ubuntu-fast/build/bin/clang+0xbafa4b)
#29 0x000077990d77dd90 __libc_start_call_main ./csu/../sysdeps/nptl/libc_start_call_main.h:58:16
#30 0x000077990d77de40 call_init ./csu/../csu/libc-start.c:128:20
#31 0x000077990d77de40 __libc_start_main ./csu/../csu/libc-start.c:379:5
#32 0x00005e08ab578095 _start (/home/buildbot/buildbot-root/llvm-clang-x86_64-sie-ubuntu-fast/build/bin/clang+0xcc1095)
/home/buildbot/buildbot-root/llvm-clang-x86_64-sie-ubuntu-fast/build/tools/clang/test/Analysis/Output/ctor.mm.script: line 4: 2204296 Aborted                 (core dumped) /home/buildbot/buildbot-root/llvm-clang-x86_64-sie-ubuntu-fast/build/bin/clang -cc1 -internal-isystem /home/buildbot/buildbot-root/llvm-clang-x86_64-sie-ubuntu-fast/build/lib/clang/21/include -nostdsysteminc -analyze -analyzer-constraints=range -setup-static-analyzer -triple i386-apple-darwin10 -DI386 -analyzer-checker=core,debug.ExprInspection -fobjc-arc -analyzer-config c++-inlining=constructors -Wno-null-dereference -std=c++11 -verify -analyzer-config eagerly-assume=false /home/buildbot/buildbot-root/llvm-clang-x86_64-sie-ubuntu-fast/llvm-project/clang/test/Analysis/ctor.mm
...

@isuckatcs
Copy link
Member

Sorry for the post-merge comment, but can we please wait for the CI to finish before merging a patch, so that we can check if everything is fine? Apparently, we broke the trunk.

Comment on lines +719 to +720
const CXXRecordDecl *TargetHeldRecord =
cast<CXXRecordDecl>(CE->getType()->getAsRecordDecl());
Copy link
Member

@isuckatcs isuckatcs May 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This cast can actually fail. See the broken testcase:

llvm-project/llvm/include/llvm/Support/Casting.h:109: static bool llvm::isa_impl_cl<To, const From*>::doit(const From*) [with To = clang::CXXRecordDecl; From = clang::RecordDecl]: Assertion `Val && "isa<> used on a null pointer"' failed.

It happened in an Objective-C test though.

struct raw_pair {
  int p1;
  int p2;
};

void testArrayNew() {
  raw_pair *p = new raw_pair[2]();
  clang_analyzer_eval(p[0].p1 == 0); // expected-warning{{TRUE}}
  clang_analyzer_eval(p[0].p2 == 0); // expected-warning{{TRUE}}
  clang_analyzer_eval(p[1].p1 == 0); // expected-warning{{TRUE}}
  clang_analyzer_eval(p[1].p2 == 0); // expected-warning{{TRUE}}
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the heads up. I re-landed the commit: b756c82

@ziqingluo-90
Copy link
Contributor Author

Re-landed: b756c82

@llvm-ci
Copy link
Collaborator

llvm-ci commented May 8, 2025

LLVM Buildbot has detected a new failure on builder llvm-x86_64-debian-dylib running on gribozavr4 while building clang at step 6 "test-build-unified-tree-check-clang".

Full details are available at: https://lab.llvm.org/buildbot/#/builders/60/builds/26748

Here is the relevant piece of the build log for the reference
Step 6 (test-build-unified-tree-check-clang) failure: test (failure)
******************** TEST 'Clang :: Analysis/ctor.mm' FAILED ********************
Exit Code: 134

Command Output (stderr):
--
/b/1/llvm-x86_64-debian-dylib/build/bin/clang -cc1 -internal-isystem /b/1/llvm-x86_64-debian-dylib/build/lib/clang/21/include -nostdsysteminc -analyze -analyzer-constraints=range -setup-static-analyzer -triple i386-apple-darwin10 -DI386 -analyzer-checker=core,debug.ExprInspection -fobjc-arc -analyzer-config c++-inlining=constructors -Wno-null-dereference -std=c++11 -verify -analyzer-config eagerly-assume=false /b/1/llvm-x86_64-debian-dylib/llvm-project/clang/test/Analysis/ctor.mm # RUN: at line 1
+ /b/1/llvm-x86_64-debian-dylib/build/bin/clang -cc1 -internal-isystem /b/1/llvm-x86_64-debian-dylib/build/lib/clang/21/include -nostdsysteminc -analyze -analyzer-constraints=range -setup-static-analyzer -triple i386-apple-darwin10 -DI386 -analyzer-checker=core,debug.ExprInspection -fobjc-arc -analyzer-config c++-inlining=constructors -Wno-null-dereference -std=c++11 -verify -analyzer-config eagerly-assume=false /b/1/llvm-x86_64-debian-dylib/llvm-project/clang/test/Analysis/ctor.mm
clang: /b/1/llvm-x86_64-debian-dylib/llvm-project/llvm/include/llvm/Support/Casting.h:109: static bool llvm::isa_impl_cl<clang::CXXRecordDecl, const clang::RecordDecl *>::doit(const From *) [To = clang::CXXRecordDecl, From = const clang::RecordDecl *]: Assertion `Val && "isa<> used on a null pointer"' failed.
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace, preprocessed source, and associated run script.
Stack dump:
0.	Program arguments: /b/1/llvm-x86_64-debian-dylib/build/bin/clang -cc1 -internal-isystem /b/1/llvm-x86_64-debian-dylib/build/lib/clang/21/include -nostdsysteminc -analyze -analyzer-constraints=range -setup-static-analyzer -triple i386-apple-darwin10 -DI386 -analyzer-checker=core,debug.ExprInspection -fobjc-arc -analyzer-config c++-inlining=constructors -Wno-null-dereference -std=c++11 -verify -analyzer-config eagerly-assume=false /b/1/llvm-x86_64-debian-dylib/llvm-project/clang/test/Analysis/ctor.mm
1.	<eof> parser at end of file
2.	While analyzing stack: 
	#0 Calling ZeroInitialization::testArrayNew()
3.	/b/1/llvm-x86_64-debian-dylib/llvm-project/clang/test/Analysis/ctor.mm:580:23: Error evaluating statement
4.	/b/1/llvm-x86_64-debian-dylib/llvm-project/clang/test/Analysis/ctor.mm:580:23: Error evaluating statement
 #0 0x00007f2700e515f7 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/b/1/llvm-x86_64-debian-dylib/build/lib/libLLVM.so.21.0git+0xfd85f7)
 #1 0x00007f2700e4f0ae llvm::sys::RunSignalHandlers() (/b/1/llvm-x86_64-debian-dylib/build/lib/libLLVM.so.21.0git+0xfd60ae)
 #2 0x00007f2700e51cca SignalHandler(int, siginfo_t*, void*) Signals.cpp:0:0
 #3 0x00007f270edc2140 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x13140)
 #4 0x00007f26ff9b0d61 raise (/lib/x86_64-linux-gnu/libc.so.6+0x38d61)
 #5 0x00007f26ff99a537 abort (/lib/x86_64-linux-gnu/libc.so.6+0x22537)
 #6 0x00007f26ff99a40f (/lib/x86_64-linux-gnu/libc.so.6+0x2240f)
 #7 0x00007f26ff9a96e2 (/lib/x86_64-linux-gnu/libc.so.6+0x316e2)
 #8 0x00007f270d6f159f clang::ento::ExprEngine::handleConstructor(clang::Expr const*, clang::ento::ExplodedNode*, clang::ento::ExplodedNodeSet&) (/b/1/llvm-x86_64-debian-dylib/build/lib/libclang-cpp.so.21.0git+0x32a359f)
 #9 0x00007f270d6cc8ed clang::ento::ExprEngine::Visit(clang::Stmt const*, clang::ento::ExplodedNode*, clang::ento::ExplodedNodeSet&) (/b/1/llvm-x86_64-debian-dylib/build/lib/libclang-cpp.so.21.0git+0x327e8ed)
#10 0x00007f270d6c9a76 clang::ento::ExprEngine::ProcessStmt(clang::Stmt const*, clang::ento::ExplodedNode*) (/b/1/llvm-x86_64-debian-dylib/build/lib/libclang-cpp.so.21.0git+0x327ba76)
#11 0x00007f270d6c9789 clang::ento::ExprEngine::processCFGElement(clang::CFGElement, clang::ento::ExplodedNode*, unsigned int, clang::ento::NodeBuilderContext*) (/b/1/llvm-x86_64-debian-dylib/build/lib/libclang-cpp.so.21.0git+0x327b789)
#12 0x00007f270d6a69b0 clang::ento::CoreEngine::HandlePostStmt(clang::CFGBlock const*, unsigned int, clang::ento::ExplodedNode*) (/b/1/llvm-x86_64-debian-dylib/build/lib/libclang-cpp.so.21.0git+0x32589b0)
#13 0x00007f270d6a5e32 clang::ento::CoreEngine::dispatchWorkItem(clang::ento::ExplodedNode*, clang::ProgramPoint, clang::ento::WorkListUnit const&) (/b/1/llvm-x86_64-debian-dylib/build/lib/libclang-cpp.so.21.0git+0x3257e32)
#14 0x00007f270d6a54ad clang::ento::CoreEngine::ExecuteWorkList(clang::LocationContext const*, unsigned int, llvm::IntrusiveRefCntPtr<clang::ento::ProgramState const>) (/b/1/llvm-x86_64-debian-dylib/build/lib/libclang-cpp.so.21.0git+0x32574ad)
#15 0x00007f270da1ea64 (anonymous namespace)::AnalysisConsumer::HandleCode(clang::Decl*, unsigned int, clang::ento::ExprEngine::InliningModes, llvm::DenseSet<clang::Decl const*, llvm::DenseMapInfo<clang::Decl const*, void>>*) AnalysisConsumer.cpp:0:0
#16 0x00007f270da1ce47 (anonymous namespace)::AnalysisConsumer::HandleTranslationUnit(clang::ASTContext&) AnalysisConsumer.cpp:0:0
#17 0x00007f270af50e56 clang::ParseAST(clang::Sema&, bool, bool) (/b/1/llvm-x86_64-debian-dylib/build/lib/libclang-cpp.so.21.0git+0xb02e56)
#18 0x00007f270d3831c6 clang::FrontendAction::Execute() (/b/1/llvm-x86_64-debian-dylib/build/lib/libclang-cpp.so.21.0git+0x2f351c6)
#19 0x00007f270d2f1002 clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/b/1/llvm-x86_64-debian-dylib/build/lib/libclang-cpp.so.21.0git+0x2ea3002)
#20 0x00007f270d423a10 clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/b/1/llvm-x86_64-debian-dylib/build/lib/libclang-cpp.so.21.0git+0x2fd5a10)
#21 0x000000000041308d cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/b/1/llvm-x86_64-debian-dylib/build/bin/clang+0x41308d)
#22 0x000000000040f4c0 ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&, llvm::ToolContext const&) driver.cpp:0:0
#23 0x000000000040eb1f clang_main(int, char**, llvm::ToolContext const&) (/b/1/llvm-x86_64-debian-dylib/build/bin/clang+0x40eb1f)
#24 0x000000000041f327 main (/b/1/llvm-x86_64-debian-dylib/build/bin/clang+0x41f327)
#25 0x00007f26ff99bd7a __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x23d7a)
#26 0x000000000040ccca _start (/b/1/llvm-x86_64-debian-dylib/build/bin/clang+0x40ccca)
/b/1/llvm-x86_64-debian-dylib/build/tools/clang/test/Analysis/Output/ctor.mm.script: line 4: 654822 Aborted                 /b/1/llvm-x86_64-debian-dylib/build/bin/clang -cc1 -internal-isystem /b/1/llvm-x86_64-debian-dylib/build/lib/clang/21/include -nostdsysteminc -analyze -analyzer-constraints=range -setup-static-analyzer -triple i386-apple-darwin10 -DI386 -analyzer-checker=core,debug.ExprInspection -fobjc-arc -analyzer-config c++-inlining=constructors -Wno-null-dereference -std=c++11 -verify -analyzer-config eagerly-assume=false /b/1/llvm-x86_64-debian-dylib/llvm-project/clang/test/Analysis/ctor.mm

--

********************


@llvm-ci
Copy link
Collaborator

llvm-ci commented May 8, 2025

LLVM Buildbot has detected a new failure on builder clang-x86_64-debian-fast running on gribozavr4 while building clang at step 6 "test-build-unified-tree-check-all".

Full details are available at: https://lab.llvm.org/buildbot/#/builders/56/builds/25255

Here is the relevant piece of the build log for the reference
Step 6 (test-build-unified-tree-check-all) failure: test (failure)
******************** TEST 'Clang :: Analysis/ctor.mm' FAILED ********************
Exit Code: 134

Command Output (stderr):
--
/b/1/clang-x86_64-debian-fast/llvm.obj/bin/clang -cc1 -internal-isystem /b/1/clang-x86_64-debian-fast/llvm.obj/lib/clang/21/include -nostdsysteminc -analyze -analyzer-constraints=range -setup-static-analyzer -triple i386-apple-darwin10 -DI386 -analyzer-checker=core,debug.ExprInspection -fobjc-arc -analyzer-config c++-inlining=constructors -Wno-null-dereference -std=c++11 -verify -analyzer-config eagerly-assume=false /b/1/clang-x86_64-debian-fast/llvm.src/clang/test/Analysis/ctor.mm # RUN: at line 1
+ /b/1/clang-x86_64-debian-fast/llvm.obj/bin/clang -cc1 -internal-isystem /b/1/clang-x86_64-debian-fast/llvm.obj/lib/clang/21/include -nostdsysteminc -analyze -analyzer-constraints=range -setup-static-analyzer -triple i386-apple-darwin10 -DI386 -analyzer-checker=core,debug.ExprInspection -fobjc-arc -analyzer-config c++-inlining=constructors -Wno-null-dereference -std=c++11 -verify -analyzer-config eagerly-assume=false /b/1/clang-x86_64-debian-fast/llvm.src/clang/test/Analysis/ctor.mm
clang: /b/1/clang-x86_64-debian-fast/llvm.src/llvm/include/llvm/Support/Casting.h:109: static bool llvm::isa_impl_cl<clang::CXXRecordDecl, const clang::RecordDecl *>::doit(const From *) [To = clang::CXXRecordDecl, From = const clang::RecordDecl *]: Assertion `Val && "isa<> used on a null pointer"' failed.
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace, preprocessed source, and associated run script.
Stack dump:
0.	Program arguments: /b/1/clang-x86_64-debian-fast/llvm.obj/bin/clang -cc1 -internal-isystem /b/1/clang-x86_64-debian-fast/llvm.obj/lib/clang/21/include -nostdsysteminc -analyze -analyzer-constraints=range -setup-static-analyzer -triple i386-apple-darwin10 -DI386 -analyzer-checker=core,debug.ExprInspection -fobjc-arc -analyzer-config c++-inlining=constructors -Wno-null-dereference -std=c++11 -verify -analyzer-config eagerly-assume=false /b/1/clang-x86_64-debian-fast/llvm.src/clang/test/Analysis/ctor.mm
1.	<eof> parser at end of file
2.	While analyzing stack: 
	#0 Calling ZeroInitialization::testArrayNew()
3.	/b/1/clang-x86_64-debian-fast/llvm.src/clang/test/Analysis/ctor.mm:580:23: Error evaluating statement
4.	/b/1/clang-x86_64-debian-fast/llvm.src/clang/test/Analysis/ctor.mm:580:23: Error evaluating statement
 #0 0x00000000039948c7 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/b/1/clang-x86_64-debian-fast/llvm.obj/bin/clang+0x39948c7)
 #1 0x000000000399237e llvm::sys::RunSignalHandlers() (/b/1/clang-x86_64-debian-fast/llvm.obj/bin/clang+0x399237e)
 #2 0x0000000003994f7a SignalHandler(int, siginfo_t*, void*) Signals.cpp:0:0
 #3 0x00007f0adef61140 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x13140)
 #4 0x00007f0adea75d61 raise (/lib/x86_64-linux-gnu/libc.so.6+0x38d61)
 #5 0x00007f0adea5f537 abort (/lib/x86_64-linux-gnu/libc.so.6+0x22537)
 #6 0x00007f0adea5f40f (/lib/x86_64-linux-gnu/libc.so.6+0x2240f)
 #7 0x00007f0adea6e6e2 (/lib/x86_64-linux-gnu/libc.so.6+0x316e2)
 #8 0x000000000583e23f clang::ento::ExprEngine::handleConstructor(clang::Expr const*, clang::ento::ExplodedNode*, clang::ento::ExplodedNodeSet&) (/b/1/clang-x86_64-debian-fast/llvm.obj/bin/clang+0x583e23f)
 #9 0x0000000005818afd clang::ento::ExprEngine::Visit(clang::Stmt const*, clang::ento::ExplodedNode*, clang::ento::ExplodedNodeSet&) (/b/1/clang-x86_64-debian-fast/llvm.obj/bin/clang+0x5818afd)
#10 0x0000000005815c86 clang::ento::ExprEngine::ProcessStmt(clang::Stmt const*, clang::ento::ExplodedNode*) (/b/1/clang-x86_64-debian-fast/llvm.obj/bin/clang+0x5815c86)
#11 0x0000000005815999 clang::ento::ExprEngine::processCFGElement(clang::CFGElement, clang::ento::ExplodedNode*, unsigned int, clang::ento::NodeBuilderContext*) (/b/1/clang-x86_64-debian-fast/llvm.obj/bin/clang+0x5815999)
#12 0x00000000057f2b60 clang::ento::CoreEngine::HandlePostStmt(clang::CFGBlock const*, unsigned int, clang::ento::ExplodedNode*) (/b/1/clang-x86_64-debian-fast/llvm.obj/bin/clang+0x57f2b60)
#13 0x00000000057f1fe2 clang::ento::CoreEngine::dispatchWorkItem(clang::ento::ExplodedNode*, clang::ProgramPoint, clang::ento::WorkListUnit const&) (/b/1/clang-x86_64-debian-fast/llvm.obj/bin/clang+0x57f1fe2)
#14 0x00000000057f165d clang::ento::CoreEngine::ExecuteWorkList(clang::LocationContext const*, unsigned int, llvm::IntrusiveRefCntPtr<clang::ento::ProgramState const>) (/b/1/clang-x86_64-debian-fast/llvm.obj/bin/clang+0x57f165d)
#15 0x00000000054e73f4 (anonymous namespace)::AnalysisConsumer::HandleCode(clang::Decl*, unsigned int, clang::ento::ExprEngine::InliningModes, llvm::DenseSet<clang::Decl const*, llvm::DenseMapInfo<clang::Decl const*, void>>*) AnalysisConsumer.cpp:0:0
#16 0x00000000054e57d7 (anonymous namespace)::AnalysisConsumer::HandleTranslationUnit(clang::ASTContext&) AnalysisConsumer.cpp:0:0
#17 0x0000000005926216 clang::ParseAST(clang::Sema&, bool, bool) (/b/1/clang-x86_64-debian-fast/llvm.obj/bin/clang+0x5926216)
#18 0x0000000004502b06 clang::FrontendAction::Execute() (/b/1/clang-x86_64-debian-fast/llvm.obj/bin/clang+0x4502b06)
#19 0x00000000044706c2 clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/b/1/clang-x86_64-debian-fast/llvm.obj/bin/clang+0x44706c2)
#20 0x00000000045e32f0 clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/b/1/clang-x86_64-debian-fast/llvm.obj/bin/clang+0x45e32f0)
#21 0x0000000000cf804d cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/b/1/clang-x86_64-debian-fast/llvm.obj/bin/clang+0xcf804d)
#22 0x0000000000cf4480 ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&, llvm::ToolContext const&) driver.cpp:0:0
#23 0x0000000000cf3adf clang_main(int, char**, llvm::ToolContext const&) (/b/1/clang-x86_64-debian-fast/llvm.obj/bin/clang+0xcf3adf)
#24 0x0000000000d042e7 main (/b/1/clang-x86_64-debian-fast/llvm.obj/bin/clang+0xd042e7)
#25 0x00007f0adea60d7a __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x23d7a)
#26 0x0000000000cf1c8a _start (/b/1/clang-x86_64-debian-fast/llvm.obj/bin/clang+0xcf1c8a)
/b/1/clang-x86_64-debian-fast/llvm.obj/tools/clang/test/Analysis/Output/ctor.mm.script: line 4: 1460420 Aborted                 /b/1/clang-x86_64-debian-fast/llvm.obj/bin/clang -cc1 -internal-isystem /b/1/clang-x86_64-debian-fast/llvm.obj/lib/clang/21/include -nostdsysteminc -analyze -analyzer-constraints=range -setup-static-analyzer -triple i386-apple-darwin10 -DI386 -analyzer-checker=core,debug.ExprInspection -fobjc-arc -analyzer-config c++-inlining=constructors -Wno-null-dereference -std=c++11 -verify -analyzer-config eagerly-assume=false /b/1/clang-x86_64-debian-fast/llvm.src/clang/test/Analysis/ctor.mm

--

********************


petrhosek pushed a commit to petrhosek/llvm-project that referenced this pull request May 8, 2025
…lvm#138594)

Previously, Static Analyzer initializes empty type fields with zeroes.
This can cause problems when those fields have no unique addresses. For
example, llvm#137252.

rdar://146753089
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang:static analyzer clang Clang issues not falling into any other category
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants