[clang] 5a42c90 - [clang] Make variables of undeduced types to have dependent alignment
Aleksandr Platonov via cfe-commits
cfe-commits at lists.llvm.org
Fri Oct 7 05:42:53 PDT 2022
Author: Aleksandr Platonov
Date: 2022-10-07T20:40:03+08:00
New Revision: 5a42c90b778c65238a54f0f1d8c8d6b35e2f6007
URL: https://github.com/llvm/llvm-project/commit/5a42c90b778c65238a54f0f1d8c8d6b35e2f6007
DIFF: https://github.com/llvm/llvm-project/commit/5a42c90b778c65238a54f0f1d8c8d6b35e2f6007.diff
LOG: [clang] Make variables of undeduced types to have dependent alignment
Without this patch `VarDecl::hasDependent()` checks only undeduced auto types, so can give false negatives result for other undeduced types.
This lead to crashes in sequence `!VarDecl::hasDepentent()` => `getDeclAlign()`.
It seems this problem appeared since D105380
Reviewed By: mizvekov
Differential Revision: https://reviews.llvm.org/D135362
Added:
Modified:
clang/lib/AST/Decl.cpp
clang/test/Sema/tls_alignment.cpp
Removed:
################################################################################
diff --git a/clang/lib/AST/Decl.cpp b/clang/lib/AST/Decl.cpp
index 49ad2230e7ca0..b326933b1d7d1 100644
--- a/clang/lib/AST/Decl.cpp
+++ b/clang/lib/AST/Decl.cpp
@@ -2581,7 +2581,7 @@ bool VarDecl::isNonEscapingByref() const {
bool VarDecl::hasDependentAlignment() const {
QualType T = getType();
- return T->isDependentType() || T->isUndeducedAutoType() ||
+ return T->isDependentType() || T->isUndeducedType() ||
llvm::any_of(specific_attrs<AlignedAttr>(), [](const AlignedAttr *AA) {
return AA->isAlignmentDependent();
});
diff --git a/clang/test/Sema/tls_alignment.cpp b/clang/test/Sema/tls_alignment.cpp
index 5a7bb2c463f37..18db565055d0e 100644
--- a/clang/test/Sema/tls_alignment.cpp
+++ b/clang/test/Sema/tls_alignment.cpp
@@ -1,6 +1,6 @@
// TLS variable cannot be aligned to more than 32 bytes on PS4.
-// RUN: %clang_cc1 -triple x86_64-scei-ps4 -fsyntax-only -verify %s
+// RUN: %clang_cc1 -triple x86_64-scei-ps4 -std=c++17 -fsyntax-only -verify %s
// A non-aligned type.
@@ -18,6 +18,12 @@ struct struct_with_aligned_field {
int some_aligned_data[12] __attribute__(( aligned(64) )); // 48 bytes of stuff, aligned to 64.
};
+// A templated type
+template <typename>
+struct templated_struct {};
+// expected-note at -1{{candidate template ignored: couldn't infer template argument ''}}
+// expected-note at -2{{candidate function template not viable: requires 1 argument, but 0 were provided}}
+
// A typedef of the aligned struct.
typedef aligned_struct another_aligned_struct;
@@ -42,6 +48,9 @@ __thread another_aligned_struct bar4; // expected-error{{alignment (6
// Variable aligned because of typedef, second case.
__thread yet_another_aligned_struct bar5; // expected-error{{alignment (64) of thread-local variable}}
+// No crash for undeduced type.
+__thread templated_struct bar6; // expected-error{{no viable constructor or deduction guide for deduction of template arguments of 'templated_struct'}}
+
int baz ()
{
return foo.some_data[0] + bar.some_data[1] + bar2.some_data[2] +
More information about the cfe-commits
mailing list