[clang] [clang][analyzer] Fixed test 'ctu-import-type-decl-definition' and ASTImporter (PR #158016)
Balázs Kéri via cfe-commits
cfe-commits at lists.llvm.org
Thu Sep 11 01:54:26 PDT 2025
https://github.com/balazske created https://github.com/llvm/llvm-project/pull/158016
The test was faulty and did not reproduce the error in ASTImporter. The previous fix #156056 for the crash was not correct, this is fixed here.
>From f02f1f25f120759fd047049c8416b51e3fac7f2a Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Bal=C3=A1zs=20K=C3=A9ri?= <balazs.keri at ericsson.com>
Date: Thu, 11 Sep 2025 10:42:34 +0200
Subject: [PATCH] [clang][analyzer] Fixed test
'ctu-import-type-decl-definition' and ASTImporter
The test was faulty and did not reproduce the error in ASTImporter.
The previous fix #156056 for the crash was not correct, this is fixed here.
---
clang/lib/AST/ASTImporter.cpp | 16 +++++++---------
.../Analysis/ctu-import-type-decl-definition.c | 16 +++++++++-------
2 files changed, 16 insertions(+), 16 deletions(-)
diff --git a/clang/lib/AST/ASTImporter.cpp b/clang/lib/AST/ASTImporter.cpp
index fe7f1e5eb0310..db14272ae5db8 100644
--- a/clang/lib/AST/ASTImporter.cpp
+++ b/clang/lib/AST/ASTImporter.cpp
@@ -1745,15 +1745,13 @@ ExpectedType ASTNodeImporter::VisitTagType(const TagType *T) {
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 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
index f74920697e977..10910e0812f3a 100644
--- a/clang/test/Analysis/ctu-import-type-decl-definition.c
+++ b/clang/test/Analysis/ctu-import-type-decl-definition.c
@@ -2,26 +2,28 @@
// RUN: mkdir -p %t
// RUN: split-file %s %t
-// RUN: %clang_cc1 -emit-pch -o %t/import.c.ast %t/import.c
+// RUN: %clang_cc1 -x c -emit-pch -o %t/import.c.ast %t/import.c
-// RUN: %clang_extdef_map -- -x c %t/import.c >> %t/externalDefMap.tmp.txt
-// RUN: sed 's/$/.ast/' %t/externalDefMap.tmp.txt >> %t/externalDefMap.txt
+// RUN: %clang_extdef_map %t/import.c -- -c -x c > %t/externalDefMap.tmp.txt
+// RUN: sed 's/$/.ast/' %t/externalDefMap.tmp.txt > %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
+// RUN: -verify %t/main.c 2>&1 | FileCheck %s
//--- main.c
// expected-no-diagnostics
+// CHECK: CTU loaded AST file:
typedef struct X_s X_t;
-unsigned long f_import(struct X_s *xPtr);
-static void freeWriteFileResources(struct X_s *xPtr) {
+long f_import(struct X_s *xPtr);
+
+static void f_main(struct X_s *xPtr) {
f_import(xPtr);
}
@@ -36,7 +38,7 @@ struct X_s {
Y_t y;
};
-unsigned long f_import(struct X_s *xPtr) {
+long f_import(struct X_s *xPtr) {
if (xPtr != 0) {
}
return 0;
More information about the cfe-commits
mailing list