forked from OSchip/llvm-project
Revert "[clang] fixes named return of variables with dependent alignment"
This reverts commit 21106388eb
.
It causes a segfault in certain cases.
This commit is contained in:
parent
51ab17b91d
commit
cbb09c5b2c
|
@ -1494,9 +1494,6 @@ public:
|
|||
NonParmVarDeclBits.EscapingByref = true;
|
||||
}
|
||||
|
||||
/// Determines if this variable's alignment is dependent.
|
||||
bool hasDependentAlignment() const;
|
||||
|
||||
/// Retrieve the variable declaration from which this variable could
|
||||
/// be instantiated, if it is an instantiation (rather than a non-template).
|
||||
VarDecl *getTemplateInstantiationPattern() const;
|
||||
|
|
|
@ -2534,13 +2534,6 @@ bool VarDecl::isNonEscapingByref() const {
|
|||
return hasAttr<BlocksAttr>() && !NonParmVarDeclBits.EscapingByref;
|
||||
}
|
||||
|
||||
bool VarDecl::hasDependentAlignment() const {
|
||||
return getType()->isDependentType() ||
|
||||
llvm::any_of(specific_attrs<AlignedAttr>(), [](const AlignedAttr *AA) {
|
||||
return AA->isAlignmentDependent();
|
||||
});
|
||||
}
|
||||
|
||||
VarDecl *VarDecl::getTemplateInstantiationPattern() const {
|
||||
const VarDecl *VD = this;
|
||||
|
||||
|
|
|
@ -13310,6 +13310,16 @@ void Sema::CheckCompleteVariableDeclaration(VarDecl *var) {
|
|||
CheckCompleteDecompositionDeclaration(DD);
|
||||
}
|
||||
|
||||
/// Determines if a variable's alignment is dependent.
|
||||
static bool hasDependentAlignment(VarDecl *VD) {
|
||||
if (VD->getType()->isDependentType())
|
||||
return true;
|
||||
for (auto *I : VD->specific_attrs<AlignedAttr>())
|
||||
if (I->isAlignmentDependent())
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
/// Check if VD needs to be dllexport/dllimport due to being in a
|
||||
/// dllexport/import function.
|
||||
void Sema::CheckStaticLocalForDllExport(VarDecl *VD) {
|
||||
|
@ -13398,7 +13408,7 @@ void Sema::FinalizeDeclaration(Decl *ThisDecl) {
|
|||
if (unsigned MaxAlign = Context.getTargetInfo().getMaxTLSAlign()) {
|
||||
// Protect the check so that it's not performed on dependent types and
|
||||
// dependent alignments (we can't determine the alignment in that case).
|
||||
if (VD->getTLSKind() && !VD->hasDependentAlignment() &&
|
||||
if (VD->getTLSKind() && !hasDependentAlignment(VD) &&
|
||||
!VD->isInvalidDecl()) {
|
||||
CharUnits MaxAlignChars = Context.toCharUnitsFromBits(MaxAlign);
|
||||
if (Context.getDeclAlign(VD) > MaxAlignChars) {
|
||||
|
|
|
@ -3395,7 +3395,7 @@ Sema::NamedReturnInfo Sema::getNamedReturnInfo(const VarDecl *VD) {
|
|||
|
||||
// Variables with higher required alignment than their type's ABI
|
||||
// alignment cannot use NRVO.
|
||||
if (!VD->hasDependentAlignment() &&
|
||||
if (!VDType->isDependentType() && VD->hasAttr<AlignedAttr>() &&
|
||||
Context.getDeclAlign(VD) > Context.getTypeAlignInChars(VDType))
|
||||
Info.S = NamedReturnInfo::MoveEligible;
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
// RUN: %clang_cc1 -std=c++20 -fblocks -Wno-return-stack-address -triple x86_64-unknown-unknown-gnu -emit-llvm -O1 -fexperimental-new-pass-manager -o - %s | FileCheck %s
|
||||
|
||||
struct alignas(4) X {
|
||||
struct X {
|
||||
X();
|
||||
X(const X&);
|
||||
X(X&&);
|
||||
|
@ -210,75 +210,3 @@ void b_attr() {
|
|||
};
|
||||
}()();
|
||||
}
|
||||
|
||||
namespace test_alignas {
|
||||
|
||||
template <int A> X t1() {
|
||||
X a [[gnu::aligned(A)]];
|
||||
return a;
|
||||
}
|
||||
|
||||
// CHECK-LABEL: define{{.*}} void @_ZN12test_alignas2t1ILi1EEE1Xv
|
||||
// CHECK: call {{.*}} @_ZN1XC1Ev
|
||||
// CHECK-NEXT: ret void
|
||||
template X t1<1>();
|
||||
|
||||
// CHECK-LABEL: define{{.*}} void @_ZN12test_alignas2t1ILi4EEE1Xv
|
||||
// CHECK: call {{.*}} @_ZN1XC1Ev
|
||||
// CHECK-NEXT: ret void
|
||||
template X t1<4>();
|
||||
|
||||
// CHECK-LABEL: define{{.*}} void @_ZN12test_alignas2t1ILi8EEE1Xv
|
||||
// CHECK: call {{.*}} @_ZN1XC1Ev
|
||||
// CHECK-NEXT: call {{.*}} @_ZN1XC1EOS_
|
||||
// CHECK-NEXT: call void @llvm.lifetime.end
|
||||
template X t1<8>();
|
||||
|
||||
template <int A> X t2() {
|
||||
X a [[gnu::aligned(1)]] [[gnu::aligned(A)]] [[gnu::aligned(2)]];
|
||||
return a;
|
||||
}
|
||||
|
||||
// CHECK-LABEL: define{{.*}} void @_ZN12test_alignas2t2ILi1EEE1Xv
|
||||
// CHECK: call {{.*}} @_ZN1XC1Ev
|
||||
// CHECK-NEXT: ret void
|
||||
template X t2<1>();
|
||||
|
||||
// CHECK-LABEL: define{{.*}} void @_ZN12test_alignas2t2ILi4EEE1Xv
|
||||
// CHECK: call {{.*}} @_ZN1XC1Ev
|
||||
// CHECK-NEXT: ret void
|
||||
template X t2<4>();
|
||||
|
||||
// CHECK-LABEL: define{{.*}} void @_ZN12test_alignas2t2ILi8EEE1Xv
|
||||
// CHECK: call {{.*}} @_ZN1XC1Ev
|
||||
// CHECK-NEXT: call {{.*}} @_ZN1XC1EOS_
|
||||
// CHECK-NEXT: call void @llvm.lifetime.end
|
||||
template X t2<8>();
|
||||
|
||||
// CHECK-LABEL: define{{.*}} void @_ZN12test_alignas2t3Ev
|
||||
// CHECK: call {{.*}} @_ZN1XC1Ev
|
||||
// CHECK-NEXT: ret void
|
||||
X t3() {
|
||||
X a [[gnu::aligned(1)]];
|
||||
return a;
|
||||
}
|
||||
|
||||
// CHECK-LABEL: define{{.*}} void @_ZN12test_alignas2t4Ev
|
||||
// CHECK: call {{.*}} @_ZN1XC1Ev
|
||||
// CHECK-NEXT: call {{.*}} @_ZN1XC1EOS_
|
||||
// CHECK-NEXT: call void @llvm.lifetime.end
|
||||
X t4() {
|
||||
X a [[gnu::aligned(8)]];
|
||||
return a;
|
||||
}
|
||||
|
||||
// CHECK-LABEL: define{{.*}} void @_ZN12test_alignas2t5Ev
|
||||
// CHECK: call {{.*}} @_ZN1XC1Ev
|
||||
// CHECK-NEXT: call {{.*}} @_ZN1XC1EOS_
|
||||
// CHECK-NEXT: call void @llvm.lifetime.end
|
||||
X t5() {
|
||||
X a [[gnu::aligned(1)]] [[gnu::aligned(8)]];
|
||||
return a;
|
||||
}
|
||||
|
||||
} // namespace test_alignas
|
||||
|
|
Loading…
Reference in New Issue