[clang] Revert "[clang] Fix of a crash 'Cannot get layout of forward declarations!' during CTU static analysis" (PR #156010)

via cfe-commits cfe-commits at lists.llvm.org
Fri Aug 29 04:53:08 PDT 2025


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-clang

Author: Balázs Kéri (balazske)

<details>
<summary>Changes</summary>

Reverts llvm/llvm-project#<!-- -->155375
Test does not work correctly on MacOS.

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


2 Files Affected:

- (modified) clang/lib/AST/ASTImporter.cpp (+1-12) 
- (removed) clang/test/Analysis/ctu-import-type-decl-definition.c (-43) 


``````````diff
diff --git a/clang/lib/AST/ASTImporter.cpp b/clang/lib/AST/ASTImporter.cpp
index d2ea60896094f..6299efaf6bbfc 100644
--- a/clang/lib/AST/ASTImporter.cpp
+++ b/clang/lib/AST/ASTImporter.cpp
@@ -1740,21 +1740,10 @@ ExpectedType ASTNodeImporter::VisitDeducedTemplateSpecializationType(
 }
 
 ExpectedType ASTNodeImporter::VisitTagType(const TagType *T) {
-  TagDecl *DeclForType = T->getOriginalDecl();
-  Expected<TagDecl *> ToDeclOrErr = import(DeclForType);
+  Expected<TagDecl *> ToDeclOrErr = import(T->getOriginalDecl());
   if (!ToDeclOrErr)
     return ToDeclOrErr.takeError();
 
-  if (DeclForType->isUsed()) {
-    // If there is a definition of the 'OriginalDecl', it should be imported to
-    // have all information for the type in the "To" AST. (In some cases no
-    // other reference may exist to the definition decl and it would not be
-    // imported otherwise.)
-    Expected<TagDecl *> ToDefDeclOrErr = import(DeclForType->getDefinition());
-    if (!ToDefDeclOrErr)
-      return ToDefDeclOrErr.takeError();
-  }
-
   if (T->isCanonicalUnqualified())
     return Importer.getToContext().getCanonicalTagType(*ToDeclOrErr);
 
diff --git a/clang/test/Analysis/ctu-import-type-decl-definition.c b/clang/test/Analysis/ctu-import-type-decl-definition.c
deleted file mode 100644
index 9855c9d8f5729..0000000000000
--- a/clang/test/Analysis/ctu-import-type-decl-definition.c
+++ /dev/null
@@ -1,43 +0,0 @@
-// RUN: rm -rf %t
-// RUN: mkdir -p %t
-// RUN: split-file %s %t
-
-// RUN: %clang_cc1 -emit-pch -o %t/import.c.ast %t/import.c
-
-// RUN: %clang_extdef_map -- -x c %t/import.c >> %t/externalDefMap.txt
-// RUN: sed -i 's/$/.ast/' %t/externalDefMap.txt
-
-// RUN: %clang_cc1 -analyze \
-// RUN:   -analyzer-checker=core \
-// RUN:   -analyzer-config experimental-enable-naive-ctu-analysis=true \
-// RUN:   -analyzer-config display-ctu-progress=true \
-// RUN:   -analyzer-config ctu-dir=%t \
-// RUN:   -verify %t/main.c
-
-//--- main.c
-
-// expected-no-diagnostics
-
-typedef struct X_s X_t;
-unsigned long f_import(struct X_s *xPtr);
-
-static void freeWriteFileResources(struct X_s *xPtr) {
-  f_import(xPtr);
-}
-
-//--- import.c
-
-typedef struct Y_s Y_t;
-
-struct Y_s {
-};
-
-struct X_s {
-  Y_t y;
-};
-
-unsigned long f_import(struct X_s *xPtr) {
-  if (xPtr != 0) {
-  }
-  return 0;
-}

``````````

</details>


https://github.com/llvm/llvm-project/pull/156010


More information about the cfe-commits mailing list