[clang] aa4bc1c - Limit Max Vector alignment on COFF targets to 8192.
Erich Keane via cfe-commits
cfe-commits at lists.llvm.org
Wed Aug 12 06:35:47 PDT 2020
Author: Erich Keane
Date: 2020-08-12T06:35:35-07:00
New Revision: aa4bc1cb7978b87bdbdb75910da0abbd27889800
URL: https://github.com/llvm/llvm-project/commit/aa4bc1cb7978b87bdbdb75910da0abbd27889800
DIFF: https://github.com/llvm/llvm-project/commit/aa4bc1cb7978b87bdbdb75910da0abbd27889800.diff
LOG: Limit Max Vector alignment on COFF targets to 8192.
COFF targets have a max object alignment of 8192, so trying to create
one with a larger size results in an unreachable in WinCOFFObjectWriter.
For the reproducer I have uses thread local storage, however other
alignments are likely affected as well.
This patch sets the MaxVectorAlign for COFF to 8192. Additionally,
though there is no longer a way to reproduce that I could find, it
correctly sets the MaxTLSAlign for COFF to that value as well, so that
if anyone comes up with a situation where this is true, it will cause an
error.
Differential Revision: https://reviews.llvm.org/D85543
Added:
Modified:
clang/include/clang/Basic/TargetInfo.h
clang/lib/Basic/Targets/X86.h
clang/test/CodeGen/alignment.c
Removed:
################################################################################
diff --git a/clang/include/clang/Basic/TargetInfo.h b/clang/include/clang/Basic/TargetInfo.h
index 004990ee3152..55db7c2d8bf6 100644
--- a/clang/include/clang/Basic/TargetInfo.h
+++ b/clang/include/clang/Basic/TargetInfo.h
@@ -100,8 +100,8 @@ struct TransferrableTargetInfo {
unsigned char MinGlobalAlign;
unsigned short NewAlign;
- unsigned short MaxVectorAlign;
- unsigned short MaxTLSAlign;
+ unsigned MaxVectorAlign;
+ unsigned MaxTLSAlign;
const llvm::fltSemantics *HalfFormat, *BFloat16Format, *FloatFormat,
*DoubleFormat, *LongDoubleFormat, *Float128Format;
@@ -1271,9 +1271,7 @@ class TargetInfo : public virtual TransferrableTargetInfo,
///
/// Gets the maximum alignment (in bits) of a TLS variable on this target.
/// Returns zero if there is no such constraint.
- unsigned short getMaxTLSAlign() const {
- return MaxTLSAlign;
- }
+ unsigned getMaxTLSAlign() const { return MaxTLSAlign; }
/// Whether target supports variable-length arrays.
bool isVLASupported() const { return VLASupported; }
diff --git a/clang/lib/Basic/Targets/X86.h b/clang/lib/Basic/Targets/X86.h
index d99358d6f806..8559ee53dca0 100644
--- a/clang/lib/Basic/Targets/X86.h
+++ b/clang/lib/Basic/Targets/X86.h
@@ -144,6 +144,11 @@ class LLVM_LIBRARY_VISIBILITY X86TargetInfo : public TargetInfo {
LongDoubleFormat = &llvm::APFloat::x87DoubleExtended();
AddrSpaceMap = &X86AddrSpaceMap;
HasStrictFP = true;
+
+ bool IsWinCOFF =
+ getTriple().isOSWindows() && getTriple().isOSBinFormatCOFF();
+ if (IsWinCOFF)
+ MaxVectorAlign = MaxTLSAlign = 8192u * getCharWidth();
}
const char *getLongDoubleMangling() const override {
diff --git a/clang/test/CodeGen/alignment.c b/clang/test/CodeGen/alignment.c
index ce0c58bee4bb..dc7a57babfc7 100644
--- a/clang/test/CodeGen/alignment.c
+++ b/clang/test/CodeGen/alignment.c
@@ -1,4 +1,5 @@
-// RUN: %clang_cc1 -triple i386-unknown-linux-gnu -emit-llvm %s -o - | FileCheck %s
+// RUN: %clang_cc1 -triple i386-unknown-linux-gnu -emit-llvm %s -o - | FileCheck %s --check-prefixes=CHECK,NONCOFF
+// RUN: %clang_cc1 -triple i386-unknown-windows-pc -emit-llvm %s -o - | FileCheck %s --check-prefixes=CHECK,COFF
__attribute((aligned(16))) float a[128];
union {int a[4]; __attribute((aligned(16))) float b[4];} b;
@@ -7,7 +8,7 @@ union {int a[4]; __attribute((aligned(16))) float b[4];} b;
// CHECK: @b = {{.*}}zeroinitializer, align 16
long long int test5[1024];
-// CHECK-DAG: @test5 = global [1024 x i64] zeroinitializer, align 8
+// CHECK-DAG: @test5 = {{.*}}global [1024 x i64] zeroinitializer, align 8
// PR5279 - Reduced alignment on typedef.
typedef int myint __attribute__((aligned(1)));
@@ -67,3 +68,11 @@ void test6(float4align64 *p) {
}
// CHECK-LABEL: @test6
// CHECK: load <4 x float>, <4 x float>* {{.*}}, align 2
+
+typedef int __attribute__((ext_vector_type(200 * 16))) BigVecTy;
+void test7() {
+ BigVecTy V;
+}
+// CHECK-LABEL: @test7
+// NONCOFF: alloca <3200 x i32>, align 16384
+// COFF: alloca <3200 x i32>, align 8192
More information about the cfe-commits
mailing list