@@ -11399,6 +11400,22 @@ static QualType mergeEnumWithInteger(ASTContext
&Context, const EnumType *ET,
return {};
}
+QualType ASTContext::mergeTagTypes(QualType LHS, QualType RHS) {
AaronBallman wrote:
I'm following the naming convention already used by ot
@@ -450,6 +453,41 @@ class StmtComparer {
};
} // namespace
+static bool
+CheckStructurallyEquivalentAttributes(StructuralEquivalenceContext &Context,
+ const Decl *D1, const Decl *D2,
+ const Decl *Prim
https://github.com/erichkeane approved this pull request.
https://github.com/llvm/llvm-project/pull/132939
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
@@ -450,6 +453,41 @@ class StmtComparer {
};
} // namespace
+static bool
+CheckStructurallyEquivalentAttributes(StructuralEquivalenceContext &Context,
+ const Decl *D1, const Decl *D2,
+ const Decl *Prim
@@ -11399,6 +11400,22 @@ static QualType mergeEnumWithInteger(ASTContext
&Context, const EnumType *ET,
return {};
}
+QualType ASTContext::mergeTagTypes(QualType LHS, QualType RHS) {
erichkeane wrote:
So this isn't really merging the TYPES, more merging tag
AaronBallman wrote:
Ping
https://github.com/llvm/llvm-project/pull/132939
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
@@ -1849,8 +1852,9 @@ TEST_F(StructuralEquivalenceCacheTest, ReturnStmtNonEq) {
Lang_CXX03);
StructuralEquivalenceContext Ctx(
- get<0>(TU)->getASTContext(), get<1>(TU)->getASTContext(),
- NonEquivalentDecls, StructuralEquivalenceKind::Default, false, false);
@@ -1913,8 +1919,9 @@ TEST_F(StructuralEquivalenceCacheTest,
Lang_CXX03);
StructuralEquivalenceContext Ctx(
- get<0>(TU)->getASTContext(), get<1>(TU)->getASTContext(),
- NonEquivalentDecls, StructuralEquivalenceKind::Default, false, false);
+ get<0>(TU)-
Sirraide wrote:
> Yeah, there's a fair amount of moving parts. This is why I want to go with
> the most conservative approach of rejecting unless the attributes are the
> same.
That seems reasonable given that we can always make this more permissive later
on.
https://github.com/llvm/llvm-pro
uecker wrote:
>
> Once that is settled, then go back to work on redeclaration/definition
> support. Possibly it'd be good to pause and ask the standards body to clarify
> how it's supposed to work first. While I think my proposed semantics above
> make sense, the standard doesn't actually _sp
@@ -450,6 +453,116 @@ class StmtComparer {
};
} // namespace
+static bool IsStructurallyEquivalent(StructuralEquivalenceContext &Context,
+ const Attr *Attr1, const Attr *Attr2) {
+ // Two attributes are structurally equivalent if they are
https://github.com/AaronBallman edited
https://github.com/llvm/llvm-project/pull/132939
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
https://github.com/AaronBallman edited
https://github.com/llvm/llvm-project/pull/132939
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
jyknight wrote:
Just to say again, I think the discussion may be crisper if we consider this as
two entirely-distinct features:
1. An expansion of "compatible type" for purposes of pointer casts/non-UB/etc.
2. The ability to provide two definitions of the same struct type in the same
scope, to
uecker wrote:
> Curiously, GCC doesn't merge the standard attributes either, it seems to do
> last-one-wins: https://godbolt.org/z/j3W7ej5Kq
I filed a bug for this: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=119526
https://github.com/llvm/llvm-project/pull/132939
AaronBallman wrote:
> However, we do have some prior art -- we're not inventing the whole idea of
> decl-merging from scratch right now. So maybe we can follow that prior art?
> For example, top-level attributes on a struct's definition can be inherited
> from a declaration in the same scope.
@@ -1886,8 +1891,9 @@ TEST_F(StructuralEquivalenceCacheTest,
VarDeclWithDifferentStorageClassNoEq) {
Lang_CXX03);
StructuralEquivalenceContext Ctx(
- get<0>(TU)->getASTContext(), get<1>(TU)->getASTContext(),
- NonEquivalentDecls, StructuralEquivalenceKind::D
uecker wrote:
> I now see there's two different parts of the problem to worry about:
>
> First case: A redeclaration in a _different_ scope. This always defines a new
> distinct type. This was valid before C23, and is still valid regardless of
> whether the type is compatible. (In contrast wit
jyknight wrote:
I now see there's two different parts of the problem to worry about:
First case: A redeclaration in a _different_ scope. This always defines a new
distinct type. This was valid before C23, and is still valid regardless of
whether the type is compatible. (In contrast with functi
@@ -450,6 +453,116 @@ class StmtComparer {
};
} // namespace
+static bool IsStructurallyEquivalent(StructuralEquivalenceContext &Context,
+ const Attr *Attr1, const Attr *Attr2) {
+ // Two attributes are structurally equivalent if they are
uecker wrote:
Another comment about attributes: Attributes should not generally affect type
compatibility (in general, but also relevant for this feature) for two reasons:
1. Standard attributes are ignorable, and this would then break. 2.
Compatibility affects aliasing, one one certainly does
@@ -450,6 +453,116 @@ class StmtComparer {
};
} // namespace
+static bool IsStructurallyEquivalent(StructuralEquivalenceContext &Context,
+ const Attr *Attr1, const Attr *Attr2) {
+ // Two attributes are structurally equivalent if they are
@@ -450,6 +453,116 @@ class StmtComparer {
};
} // namespace
+static bool IsStructurallyEquivalent(StructuralEquivalenceContext &Context,
+ const Attr *Attr1, const Attr *Attr2) {
+ // Two attributes are structurally equivalent if they are
@@ -450,6 +453,116 @@ class StmtComparer {
};
} // namespace
+static bool IsStructurallyEquivalent(StructuralEquivalenceContext &Context,
+ const Attr *Attr1, const Attr *Attr2) {
+ // Two attributes are structurally equivalent if they are
@@ -450,6 +453,116 @@ class StmtComparer {
};
} // namespace
+static bool IsStructurallyEquivalent(StructuralEquivalenceContext &Context,
+ const Attr *Attr1, const Attr *Attr2) {
+ // Two attributes are structurally equivalent if they are
@@ -450,6 +453,116 @@ class StmtComparer {
};
} // namespace
+static bool IsStructurallyEquivalent(StructuralEquivalenceContext &Context,
+ const Attr *Attr1, const Attr *Attr2) {
+ // Two attributes are structurally equivalent if they are
@@ -450,6 +453,116 @@ class StmtComparer {
};
} // namespace
+static bool IsStructurallyEquivalent(StructuralEquivalenceContext &Context,
+ const Attr *Attr1, const Attr *Attr2) {
+ // Two attributes are structurally equivalent if they are
uecker wrote:
BTW: I did not push for this feature to be exposed in earlier language modes
because GCC will ship with GNU C23 by default with GCC 15. GCC 15 already saw
distribution-wide testing in Redhat and Debian and from this experience I do
not expect any problems related to this featur
uecker wrote:
> It seems to me that we could simplify the implementation by being a bit more
> literal in the interpretation of the requirements: look only at the type,
> alignment, name, and bitfield-width of members. Just don't bother checking
> other stuff
>
> I'd hope it can look more lik
jyknight wrote:
It seems to me that we could simplify the implementation by being a bit more
literal in the interpretation of the requirements: look only at the type,
alignment, name, and bitfield-width of members. Just don't bother checking
other stuff
I'd hope it can look more like a simple
@@ -0,0 +1,472 @@
+// RUN: %clang_cc1 -fsyntax-only -std=c23 -pedantic -Wall -Wno-comment
-verify=both,c23 %s
+// RUN: %clang_cc1 -fsyntax-only -std=c17 -pedantic -Wall -Wno-comment
-Wno-c23-extensions -verify=both,c17 %s
+
+/* WG14 N3037:
+ * Improved tag compatibility
+ *
+ *
@@ -450,6 +453,116 @@ class StmtComparer {
};
} // namespace
+static bool IsStructurallyEquivalent(StructuralEquivalenceContext &Context,
+ const Attr *Attr1, const Attr *Attr2) {
+ // Two attributes are structurally equivalent if they are
@@ -1454,6 +1567,12 @@ static bool
IsStructurallyEquivalent(StructuralEquivalenceContext &Context,
QualType Owner2Type) {
const auto *Owner2 = cast(Field2->getDeclContext());
+ // In C23 mode, check for structural equivalence of attribu
@@ -450,6 +453,116 @@ class StmtComparer {
};
} // namespace
+static bool IsStructurallyEquivalent(StructuralEquivalenceContext &Context,
+ const Attr *Attr1, const Attr *Attr2) {
+ // Two attributes are structurally equivalent if they are
github-actions[bot] wrote:
:warning: C/C++ code formatter, clang-format found issues in your code.
:warning:
You can test this locally with the following command:
``bash
git-clang-format --diff 9b1f905b483a2b42e4681bbef42b2641f8ccf5ad
2bde3a9c6eb5e23b0e9274122bd6f9a50ffa3bc4 --e
@@ -1496,9 +1615,37 @@ static bool
IsStructurallyEquivalent(StructuralEquivalenceContext &Context,
return false;
}
- if (Field1->isBitField())
-return IsStructurallyEquivalent(Context, Field1->getBitWidth(),
-Field2->getBitWidth(
@@ -450,6 +453,116 @@ class StmtComparer {
};
} // namespace
+static bool IsStructurallyEquivalent(StructuralEquivalenceContext &Context,
+ const Attr *Attr1, const Attr *Attr2) {
+ // Two attributes are structurally equivalent if they are
@@ -43,6 +43,9 @@ struct StructuralEquivalenceContext {
/// key: (from, to, IgnoreTemplateParmDepth)
using NonEquivalentDeclSet = llvm::DenseSet>;
+ /// The language options to use for making a structural equivalence check.
+ const LangOptions &LangOpts;
+
--
@@ -0,0 +1,472 @@
+// RUN: %clang_cc1 -fsyntax-only -std=c23 -pedantic -Wall -Wno-comment
-verify=both,c23 %s
+// RUN: %clang_cc1 -fsyntax-only -std=c17 -pedantic -Wall -Wno-comment
-Wno-c23-extensions -verify=both,c17 %s
+
+/* WG14 N3037:
+ * Improved tag compatibility
+ *
+ *
@@ -0,0 +1,472 @@
+// RUN: %clang_cc1 -fsyntax-only -std=c23 -pedantic -Wall -Wno-comment
-verify=both,c23 %s
+// RUN: %clang_cc1 -fsyntax-only -std=c17 -pedantic -Wall -Wno-comment
-Wno-c23-extensions -verify=both,c17 %s
+
+/* WG14 N3037:
+ * Improved tag compatibility
+ *
+ *
@@ -1496,9 +1615,37 @@ static bool
IsStructurallyEquivalent(StructuralEquivalenceContext &Context,
return false;
}
- if (Field1->isBitField())
-return IsStructurallyEquivalent(Context, Field1->getBitWidth(),
-Field2->getBitWidth(
@@ -1496,9 +1615,37 @@ static bool
IsStructurallyEquivalent(StructuralEquivalenceContext &Context,
return false;
}
- if (Field1->isBitField())
-return IsStructurallyEquivalent(Context, Field1->getBitWidth(),
-Field2->getBitWidth(
@@ -450,6 +453,116 @@ class StmtComparer {
};
} // namespace
+static bool IsStructurallyEquivalent(StructuralEquivalenceContext &Context,
+ const Attr *Attr1, const Attr *Attr2) {
+ // Two attributes are structurally equivalent if they are
@@ -450,6 +453,116 @@ class StmtComparer {
};
} // namespace
+static bool IsStructurallyEquivalent(StructuralEquivalenceContext &Context,
+ const Attr *Attr1, const Attr *Attr2) {
+ // Two attributes are structurally equivalent if they are
@@ -478,16 +478,24 @@ def warn_odr_function_type_inconsistent : Warning<
"external function %0 declared with incompatible types in different "
"translation units (%1 vs. %2)">,
InGroup;
+def err_odr_attr_inconsistent : Error<
+ "attribute %0 is incompatible%select{| in d
@@ -450,6 +453,116 @@ class StmtComparer {
};
} // namespace
+static bool IsStructurallyEquivalent(StructuralEquivalenceContext &Context,
+ const Attr *Attr1, const Attr *Attr2) {
+ // Two attributes are structurally equivalent if they are
@@ -43,6 +43,9 @@ struct StructuralEquivalenceContext {
/// key: (from, to, IgnoreTemplateParmDepth)
using NonEquivalentDeclSet = llvm::DenseSet>;
+ /// The language options to use for making a structural equivalence check.
+ const LangOptions &LangOpts;
+
--
@@ -450,6 +453,116 @@ class StmtComparer {
};
} // namespace
+static bool IsStructurallyEquivalent(StructuralEquivalenceContext &Context,
+ const Attr *Attr1, const Attr *Attr2) {
+ // Two attributes are structurally equivalent if they are
@@ -450,6 +453,116 @@ class StmtComparer {
};
} // namespace
+static bool IsStructurallyEquivalent(StructuralEquivalenceContext &Context,
+ const Attr *Attr1, const Attr *Attr2) {
+ // Two attributes are structurally equivalent if they are
@@ -450,6 +453,116 @@ class StmtComparer {
};
} // namespace
+static bool IsStructurallyEquivalent(StructuralEquivalenceContext &Context,
+ const Attr *Attr1, const Attr *Attr2) {
+ // Two attributes are structurally equivalent if they are
@@ -1454,6 +1567,12 @@ static bool
IsStructurallyEquivalent(StructuralEquivalenceContext &Context,
QualType Owner2Type) {
const auto *Owner2 = cast(Field2->getDeclContext());
+ // In C23 mode, check for structural equivalence of attribu
@@ -0,0 +1,472 @@
+// RUN: %clang_cc1 -fsyntax-only -std=c23 -pedantic -Wall -Wno-comment
-verify=both,c23 %s
+// RUN: %clang_cc1 -fsyntax-only -std=c17 -pedantic -Wall -Wno-comment
-Wno-c23-extensions -verify=both,c17 %s
+
+/* WG14 N3037:
+ * Improved tag compatibility
+ *
+ *
https://github.com/shafik edited
https://github.com/llvm/llvm-project/pull/132939
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
@@ -0,0 +1,472 @@
+// RUN: %clang_cc1 -fsyntax-only -std=c23 -pedantic -Wall -Wno-comment
-verify=both,c23 %s
+// RUN: %clang_cc1 -fsyntax-only -std=c17 -pedantic -Wall -Wno-comment
-Wno-c23-extensions -verify=both,c17 %s
+
+/* WG14 N3037:
+ * Improved tag compatibility
+ *
+ *
https://github.com/shafik commented:
Second round of comments, I may make a third go around but I wouldn't wait for
me.
https://github.com/llvm/llvm-project/pull/132939
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi
@@ -0,0 +1,472 @@
+// RUN: %clang_cc1 -fsyntax-only -std=c23 -pedantic -Wall -Wno-comment
-verify=both,c23 %s
+// RUN: %clang_cc1 -fsyntax-only -std=c17 -pedantic -Wall -Wno-comment
-Wno-c23-extensions -verify=both,c17 %s
+
+/* WG14 N3037:
+ * Improved tag compatibility
+ *
+ *
@@ -1964,8 +1972,9 @@ TEST_F(StructuralEquivalenceCacheTest, SpecialNonEq) {
Lang_CXX03);
StructuralEquivalenceContext Ctx(
- get<0>(TU)->getASTContext(), get<1>(TU)->getASTContext(),
- NonEquivalentDecls, StructuralEquivalenceKind::Default, false, false);
+
@@ -4567,8 +4567,9 @@ namespace {
Reader.getOwningModuleFile(Cat)) {
StructuralEquivalenceContext::NonEquivalentDeclSet
NonEquivalentDecls;
StructuralEquivalenceContext Ctx(
- Cat->getASTContext(), Existing->getASTCo
https://github.com/shafik edited
https://github.com/llvm/llvm-project/pull/132939
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
https://github.com/shafik commented:
A lot of nits
https://github.com/llvm/llvm-project/pull/132939
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
@@ -156,11 +158,11 @@ struct StructuralEquivalenceTest : ::testing::Test {
StructuralEquivalenceContext::NonEquivalentDeclSet NonEquivalentDecls01;
StructuralEquivalenceContext::NonEquivalentDeclSet NonEquivalentDecls10;
StructuralEquivalenceContext Ctx01(
-
@@ -2003,8 +2012,9 @@ TEST_F(StructuralEquivalenceCacheTest, Cycle) {
Lang_CXX03);
StructuralEquivalenceContext Ctx(
- get<0>(TU)->getASTContext(), get<1>(TU)->getASTContext(),
- NonEquivalentDecls, StructuralEquivalenceKind::Default, false, false);
+ ge
@@ -11432,6 +11433,22 @@ static QualType mergeEnumWithInteger(ASTContext
&Context, const EnumType *ET,
return {};
}
+QualType ASTContext::mergeTagTypes(QualType LHS, QualType RHS) {
+ // C17 and earlier and C++ disallow two tag definitions within the same TU
+ // from bei
@@ -2080,9 +2090,9 @@ TEST_F(StructuralEquivalenceCacheTest, TemplateParmDepth)
{
EXPECT_FALSE(isInNonEqCache(std::make_pair(NonEqDecl0, NonEqDecl1), true));
StructuralEquivalenceContext Ctx_IgnoreTemplateParmDepth(
- get<0>(TU)->getASTContext(), get<1>(TU)->getASTCo
@@ -1826,8 +1828,9 @@ TEST_F(StructuralEquivalenceCacheTest, SimpleNonEq) {
Lang_CXX03);
StructuralEquivalenceContext Ctx(
- get<0>(TU)->getASTContext(), get<1>(TU)->getASTContext(),
- NonEquivalentDecls, StructuralEquivalenceKind::Default, false, false);
+
@@ -1868,8 +1872,9 @@ TEST_F(StructuralEquivalenceCacheTest, VarDeclNoEq) {
Lang_CXX03);
StructuralEquivalenceContext Ctx(
- get<0>(TU)->getASTContext(), get<1>(TU)->getASTContext(),
- NonEquivalentDecls, StructuralEquivalenceKind::Default, false, false);
+
@@ -1932,8 +1939,9 @@ TEST_F(StructuralEquivalenceCacheTest,
VarDeclWithInitNoEq) {
Lang_CXX03);
StructuralEquivalenceContext Ctx(
- get<0>(TU)->getASTContext(), get<1>(TU)->getASTContext(),
- NonEquivalentDecls, StructuralEquivalenceKind::Default, false, fa
@@ -9089,8 +9089,8 @@ bool Sema::hasStructuralCompatLayout(Decl *D, Decl
*Suggested) {
// FIXME: Add a specific mode for C11 6.2.7/1 in StructuralEquivalenceContext
// and isolate from other C++ specific checks.
StructuralEquivalenceContext Ctx(
- D->getASTContext()
@@ -11432,6 +11433,22 @@ static QualType mergeEnumWithInteger(ASTContext
&Context, const EnumType *ET,
return {};
}
+QualType ASTContext::mergeTagTypes(QualType LHS, QualType RHS) {
+ // C17 and earlier and C++ disallow two tag definitions within the same TU
+ // from bei
@@ -0,0 +1,456 @@
+// RUN: %clang_cc1 -fsyntax-only -std=c23 -pedantic -Wall -Wno-comment
-verify=both,c23 %s
+// RUN: %clang_cc1 -fsyntax-only -std=c17 -pedantic -Wall -Wno-comment
-Wno-c23-extensions -verify=both,c17 %s
+
+/* WG14 N3037:
+ * Improved tag compatibility
+ *
+ *
@@ -0,0 +1,456 @@
+// RUN: %clang_cc1 -fsyntax-only -std=c23 -pedantic -Wall -Wno-comment
-verify=both,c23 %s
+// RUN: %clang_cc1 -fsyntax-only -std=c17 -pedantic -Wall -Wno-comment
-Wno-c23-extensions -verify=both,c17 %s
+
+/* WG14 N3037:
+ * Improved tag compatibility
+ *
+ *
@@ -0,0 +1,456 @@
+// RUN: %clang_cc1 -fsyntax-only -std=c23 -pedantic -Wall -Wno-comment
-verify=both,c23 %s
+// RUN: %clang_cc1 -fsyntax-only -std=c17 -pedantic -Wall -Wno-comment
-Wno-c23-extensions -verify=both,c17 %s
+
+/* WG14 N3037:
+ * Improved tag compatibility
+ *
+ *
@@ -0,0 +1,456 @@
+// RUN: %clang_cc1 -fsyntax-only -std=c23 -pedantic -Wall -Wno-comment
-verify=both,c23 %s
+// RUN: %clang_cc1 -fsyntax-only -std=c17 -pedantic -Wall -Wno-comment
-Wno-c23-extensions -verify=both,c17 %s
+
+/* WG14 N3037:
+ * Improved tag compatibility
+ *
+ *
@@ -1905,54 +2073,84 @@ static bool
IsStructurallyEquivalent(StructuralEquivalenceContext &Context,
// Compare the definitions of these two enums. If either or both are
// incomplete (i.e. forward declared), we assume that they are equivalent.
+ // In C23, the order of t
@@ -450,6 +453,116 @@ class StmtComparer {
};
} // namespace
+static bool IsStructurallyEquivalent(StructuralEquivalenceContext &Context,
+ const Attr *Attr1, const Attr *Attr2) {
+ // Two attributes are structurally equivalent if they are
75 matches
Mail list logo