forked from llvm/llvm-project
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[clang][ASTImporter] Fix a bug when importing CXXDefaultInitExpr.
The "in-class initializer" expression should be set in the field of a default initialization expression before this expression node is created. The `CXXDefaultInitExpr` objects are created after the AST is loaded and at import not present in the "To" AST. And the in-class initializers of the used fields can be missing too, these must be set at import. This fixes a github issue llvm#54061. Reviewed By: martong Differential Revision: https://reviews.llvm.org/D120824
- Loading branch information
Showing
5 changed files
with
249 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
clang/test/Analysis/Inputs/ctu-cxxdefaultinitexpr-import.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
namespace QHashPrivate { | ||
template <typename> int b; | ||
struct Data; | ||
} // namespace QHashPrivate | ||
|
||
struct QDomNodePrivate {}; | ||
template <typename = struct QString> struct QMultiHash { | ||
QHashPrivate::Data *d = nullptr; | ||
}; | ||
|
||
struct QDomNamedNodeMapPrivate { | ||
QMultiHash<> map; | ||
}; | ||
struct QDomElementPrivate : QDomNodePrivate { | ||
QDomElementPrivate(); | ||
void importee(); | ||
QMultiHash<> *m_attr = nullptr; | ||
}; | ||
// --------- common part end --------- | ||
|
||
QDomElementPrivate::QDomElementPrivate() : m_attr{new QMultiHash<>} {} | ||
void QDomElementPrivate::importee() { (void)QMultiHash<>{}; } | ||
struct foo { | ||
QDomElementPrivate m = {}; | ||
static const int value = (QHashPrivate::b<foo>, 22); | ||
}; |
4 changes: 4 additions & 0 deletions
4
clang/test/Analysis/Inputs/ctu-cxxdefaultinitexpr-import.cpp.externalDefMap.ast-dump.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
14:c:@S@foo@value ctu-cxxdefaultinitexpr-import.cpp.ast | ||
35:c:@S@QDomElementPrivate@F@importee# ctu-cxxdefaultinitexpr-import.cpp.ast | ||
45:c:@S@QDomElementPrivate@F@QDomElementPrivate# ctu-cxxdefaultinitexpr-import.cpp.ast | ||
39:c:@S@QDomNodePrivate@F@QDomNodePrivate# ctu-cxxdefaultinitexpr-import.cpp.ast |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
// RUN: rm -rf %t && mkdir %t | ||
// RUN: mkdir -p %t/ctudir | ||
// RUN: %clang_cc1 -triple x86_64-pc-linux-gnu -std=c++17 \ | ||
// RUN: -emit-pch -o %t/ctudir/ctu-cxxdefaultinitexpr-import.cpp.ast %S/Inputs/ctu-cxxdefaultinitexpr-import.cpp | ||
// RUN: cp %S/Inputs/ctu-cxxdefaultinitexpr-import.cpp.externalDefMap.ast-dump.txt %t/ctudir/externalDefMap.txt | ||
// RUN: %clang_cc1 -triple x86_64-pc-linux-gnu -fsyntax-only -std=c++17 -analyze \ | ||
// RUN: -analyzer-checker=core \ | ||
// RUN: -analyzer-config experimental-enable-naive-ctu-analysis=true \ | ||
// RUN: -analyzer-config ctu-dir=%t/ctudir \ | ||
// RUN: -verify %s | ||
|
||
// Check that importing this code does not cause crash. | ||
// expected-no-diagnostics | ||
|
||
namespace QHashPrivate { | ||
template <typename> int b; | ||
struct Data; | ||
} // namespace QHashPrivate | ||
|
||
struct QDomNodePrivate {}; | ||
template <typename = struct QString> struct QMultiHash { | ||
QHashPrivate::Data *d = nullptr; | ||
}; | ||
|
||
struct QDomNamedNodeMapPrivate { | ||
QMultiHash<> map; | ||
}; | ||
struct QDomElementPrivate : QDomNodePrivate { | ||
QDomElementPrivate(); | ||
void importee(); | ||
QMultiHash<> *m_attr = nullptr; | ||
}; | ||
// --------- common part end --------- | ||
|
||
void importer(QDomElementPrivate x) { x.importee(); } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters