[llvm-branch-commits] [clang] f1ca50a - D88665 id 295585 [ASTImporter][AST] Fix structural equivalency crash on dependent FieldDecl
Gabor Marton via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Fri Oct 16 01:37:38 PDT 2020
Author: Gabor Marton
Date: 2020-10-14T11:15:06+02:00
New Revision: f1ca50a5094653463e350daa6c508885f61f11b4
URL: https://github.com/llvm/llvm-project/commit/f1ca50a5094653463e350daa6c508885f61f11b4
DIFF: https://github.com/llvm/llvm-project/commit/f1ca50a5094653463e350daa6c508885f61f11b4.diff
LOG: D88665 id 295585 [ASTImporter][AST] Fix structural equivalency crash on dependent FieldDecl
Added:
Modified:
clang/lib/AST/ASTStructuralEquivalence.cpp
clang/unittests/AST/StructuralEquivalenceTest.cpp
Removed:
################################################################################
diff --git a/clang/lib/AST/ASTStructuralEquivalence.cpp b/clang/lib/AST/ASTStructuralEquivalence.cpp
index 8b5b2444f1e2..3dcd4159dc0b 100644
--- a/clang/lib/AST/ASTStructuralEquivalence.cpp
+++ b/clang/lib/AST/ASTStructuralEquivalence.cpp
@@ -1071,6 +1071,10 @@ static bool IsStructurallyEquivalent(StructuralEquivalenceContext &Context,
}
if (Field1->isBitField()) {
+ bool isVD1 = Field1->getBitWidth()->isValueDependent();
+ bool isVD2 = Field2->getBitWidth()->isValueDependent();
+ if (isVD1 || isVD2)
+ return isVD1 && isVD2;
// Make sure that the bit-fields are the same length.
unsigned Bits1 = Field1->getBitWidthValue(Context.FromCtx);
unsigned Bits2 = Field2->getBitWidthValue(Context.ToCtx);
diff --git a/clang/unittests/AST/StructuralEquivalenceTest.cpp b/clang/unittests/AST/StructuralEquivalenceTest.cpp
index 2b5ce0fed51d..b5aff49eaaee 100644
--- a/clang/unittests/AST/StructuralEquivalenceTest.cpp
+++ b/clang/unittests/AST/StructuralEquivalenceTest.cpp
@@ -906,6 +906,12 @@ TEST_F(StructuralEquivalenceTemplateTest, DifferentTemplateArgKind) {
EXPECT_FALSE(testStructuralMatch(t));
}
+TEST_F(StructuralEquivalenceTemplateTest, DependentFieldDecl) {
+ const char *Code = "template <class T> class foo { int a : sizeof(T); };";
+ auto t = makeNamedDecls(Code, Code, Lang_CXX03);
+ EXPECT_TRUE(testStructuralMatch(t));
+}
+
TEST_F(StructuralEquivalenceTemplateTest, ExplicitBoolSame) {
auto Decls = makeNamedDecls(
"template <bool b> struct foo {explicit(b) foo(int);};",
More information about the llvm-branch-commits
mailing list