Skip to content

Commit

Permalink
Merged master:bc029fa6c5c into amd-gfx:46e9f135e19
Browse files Browse the repository at this point in the history
Local branch amd-gfx 46e9f13 Merged master:c7878ad231e into amd-gfx:7c4ecec51ae
Remote branch master bc029fa [clangd] Still need pthreads in clangDaemon.
  • Loading branch information
Sw authored and Sw committed Apr 29, 2020
2 parents 46e9f13 + bc029fa commit 65be4e0
Show file tree
Hide file tree
Showing 26 changed files with 872 additions and 262 deletions.
1 change: 1 addition & 0 deletions clang-tools-extra/clangd/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ add_clang_library(clangDaemon
clangToolingRefactoring
clangToolingSyntax
clangdSupport
${LLVM_PTHREAD_LIB}
${ALL_CLANG_TIDY_CHECKS}
)

Expand Down
37 changes: 34 additions & 3 deletions clang/lib/CodeGen/TargetInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1822,6 +1822,15 @@ ABIArgInfo X86_32ABIInfo::classifyArgumentType(QualType Ty,
return ABIArgInfo::getExtend(Ty);
}

if (const auto * EIT = Ty->getAs<ExtIntType>()) {
if (EIT->getNumBits() <= 64) {
if (InReg)
return ABIArgInfo::getDirectInReg();
return ABIArgInfo::getDirect();
}
return getIndirectResult(Ty, /*ByVal=*/false, State);
}

if (InReg)
return ABIArgInfo::getDirectInReg();
return ABIArgInfo::getDirect();
Expand Down Expand Up @@ -2785,6 +2794,15 @@ void X86_64ABIInfo::classify(QualType Ty, uint64_t OffsetBase,
return;
}

if (const auto *EITy = Ty->getAs<ExtIntType>()) {
if (EITy->getNumBits() <= 64)
Current = Integer;
else if (EITy->getNumBits() <= 128)
Lo = Hi = Integer;
// Larger values need to get passed in memory.
return;
}

if (const ConstantArrayType *AT = getContext().getAsConstantArrayType(Ty)) {
// Arrays are treated like structures.

Expand Down Expand Up @@ -2959,8 +2977,9 @@ ABIArgInfo X86_64ABIInfo::getIndirectReturnResult(QualType Ty) const {
if (const EnumType *EnumTy = Ty->getAs<EnumType>())
Ty = EnumTy->getDecl()->getIntegerType();

return (Ty->isPromotableIntegerType() ? ABIArgInfo::getExtend(Ty)
: ABIArgInfo::getDirect());
if (!Ty->isExtIntType())
return (Ty->isPromotableIntegerType() ? ABIArgInfo::getExtend(Ty)
: ABIArgInfo::getDirect());
}

return getNaturalAlignIndirect(Ty);
Expand Down Expand Up @@ -2992,7 +3011,8 @@ ABIArgInfo X86_64ABIInfo::getIndirectResult(QualType Ty,
// the argument in the free register. This does not seem to happen currently,
// but this code would be much safer if we could mark the argument with
// 'onstack'. See PR12193.
if (!isAggregateTypeForABI(Ty) && !IsIllegalVectorType(Ty)) {
if (!isAggregateTypeForABI(Ty) && !IsIllegalVectorType(Ty) &&
!Ty->isExtIntType()) {
// Treat an enum type as its underlying type.
if (const EnumType *EnumTy = Ty->getAs<EnumType>())
Ty = EnumTy->getDecl()->getIntegerType();
Expand Down Expand Up @@ -4083,6 +4103,17 @@ ABIArgInfo WinX86_64ABIInfo::classify(QualType Ty, unsigned &FreeSSERegs,
}
}

if (Ty->isExtIntType()) {
// MS x64 ABI requirement: "Any argument that doesn't fit in 8 bytes, or is
// not 1, 2, 4, or 8 bytes, must be passed by reference."
// However, non-power-of-two _ExtInts will be passed as 1,2,4 or 8 bytes
// anyway as long is it fits in them, so we don't have to check the power of
// 2.
if (Width <= 64)
return ABIArgInfo::getDirect();
return ABIArgInfo::getIndirect(Align, /*ByVal=*/false);
}

return ABIArgInfo::getDirect();
}

Expand Down
12 changes: 12 additions & 0 deletions clang/lib/Driver/ToolChains/MinGW.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include "llvm/Option/ArgList.h"
#include "llvm/Support/FileSystem.h"
#include "llvm/Support/Path.h"
#include "llvm/Support/VirtualFileSystem.h"
#include <system_error>

using namespace clang::diag;
Expand Down Expand Up @@ -198,6 +199,17 @@ void tools::MinGW::Linker::ConstructJob(Compilation &C, const JobAction &JA,

Args.AddAllArgs(CmdArgs, options::OPT_L);
TC.AddFilePathLibArgs(Args, CmdArgs);

// Add the compiler-rt library directories if they exist to help
// the linker find the various sanitizer, builtin, and profiling runtimes.
for (const auto &LibPath : TC.getLibraryPaths()) {
if (TC.getVFS().exists(LibPath))
CmdArgs.push_back(Args.MakeArgString("-L" + LibPath));
}
auto CRTPath = TC.getCompilerRTPath();
if (TC.getVFS().exists(CRTPath))
CmdArgs.push_back(Args.MakeArgString("-L" + CRTPath));

AddLinkerInputs(TC, Inputs, Args, CmdArgs, JA);

// TODO: Add profile stuff here
Expand Down
42 changes: 42 additions & 0 deletions clang/test/CodeGen/ext-int-cc.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// RUN: %clang_cc1 -triple x86_64-gnu-linux -O3 -disable-llvm-passes -emit-llvm -o - %s | FileCheck %s --check-prefixes=LIN64
// RUN: %clang_cc1 -triple x86_64-windows-pc -O3 -disable-llvm-passes -emit-llvm -o - %s | FileCheck %s --check-prefixes=WIN64
// RUN: %clang_cc1 -triple i386-gnu-linux -O3 -disable-llvm-passes -emit-llvm -o - %s | FileCheck %s --check-prefixes=LIN32
// RUN: %clang_cc1 -triple i386-windows-pc -O3 -disable-llvm-passes -emit-llvm -o - %s | FileCheck %s --check-prefixes=WIN32

// Make sure 128 and 64 bit versions are passed like integers, and that >128
// is passed indirectly.
void ParamPassing(_ExtInt(129) a, _ExtInt(128) b, _ExtInt(64) c) {}
// LIN64: define void @ParamPassing(i129* byval(i129) align 8 %{{.+}}, i64 %{{.+}}, i64 %{{.+}}, i64 %{{.+}})
// WIN64: define dso_local void @ParamPassing(i129* %{{.+}}, i128* %{{.+}}, i64 %{{.+}})
// LIN32: define void @ParamPassing(i129* %{{.+}}, i128* %{{.+}}, i64 %{{.+}})
// WIN32: define dso_local void @ParamPassing(i129* %{{.+}}, i128* %{{.+}}, i64 %{{.+}})
void ParamPassing2(_ExtInt(129) a, _ExtInt(127) b, _ExtInt(63) c) {}
// LIN64: define void @ParamPassing2(i129* byval(i129) align 8 %{{.+}}, i64 %{{.+}}, i64 %{{.+}}, i64 %{{.+}})
// WIN64: define dso_local void @ParamPassing2(i129* %{{.+}}, i127* %{{.+}}, i63 %{{.+}})
// LIN32: define void @ParamPassing2(i129* %{{.+}}, i127* %{{.+}}, i63 %{{.+}})
// WIN32: define dso_local void @ParamPassing2(i129* %{{.+}}, i127* %{{.+}}, i63 %{{.+}})
_ExtInt(63) ReturnPassing(){}
// LIN64: define i64 @ReturnPassing(
// WIN64: define dso_local i63 @ReturnPassing(
// LIN32: define i63 @ReturnPassing(
// WIN32: define dso_local i63 @ReturnPassing(
_ExtInt(64) ReturnPassing2(){}
// LIN64: define i64 @ReturnPassing2(
// WIN64: define dso_local i64 @ReturnPassing2(
// LIN32: define i64 @ReturnPassing2(
// WIN32: define dso_local i64 @ReturnPassing2(
_ExtInt(127) ReturnPassing3(){}
// LIN64: define { i64, i64 } @ReturnPassing3(
// WIN64: define dso_local void @ReturnPassing3(i127* noalias sret
// LIN32: define i127 @ReturnPassing3(
// WIN32: define dso_local i127 @ReturnPassing3(
_ExtInt(128) ReturnPassing4(){}
// LIN64: define { i64, i64 } @ReturnPassing4(
// WIN64: define dso_local void @ReturnPassing4(i128* noalias sret
// LIN32: define i128 @ReturnPassing4(
// WIN32: define dso_local i128 @ReturnPassing4(
_ExtInt(129) ReturnPassing5(){}
// LIN64: define void @ReturnPassing5(i129* noalias sret
// WIN64: define dso_local void @ReturnPassing5(i129* noalias sret
// LIN32: define i129 @ReturnPassing5(
// WIN32: define dso_local i129 @ReturnPassing5(
49 changes: 32 additions & 17 deletions clang/test/CodeGen/ext-int-sanitizer.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// RUN: %clang_cc1 -triple x86_64-gnu-linux -fsanitize=array-bounds,enum,float-cast-overflow,integer-divide-by-zero,implicit-unsigned-integer-truncation,implicit-signed-integer-truncation,implicit-integer-sign-change,unsigned-integer-overflow,signed-integer-overflow,shift-base,shift-exponent -O3 -disable-llvm-passes -emit-llvm -o - %s | FileCheck %s
// RUN: %clang_cc1 -triple x86_64-gnu-linux -fsanitize=array-bounds,enum,float-cast-overflow,integer-divide-by-zero,implicit-unsigned-integer-truncation,implicit-signed-integer-truncation,implicit-integer-sign-change,unsigned-integer-overflow,signed-integer-overflow,shift-base,shift-exponent -O3 -disable-llvm-passes -emit-llvm -o - %s | FileCheck %s


// CHECK: define void @_Z6BoundsRA10_KiU7_ExtIntILi15EEi
Expand Down Expand Up @@ -56,9 +56,11 @@ void UIntTruncation(unsigned _ExtInt(35) E, unsigned int i, unsigned long long l

i = E;
// CHECK: %[[LOADE:.+]] = load i35
// CHECK: %[[CONV:.+]] = trunc i35 %[[LOADE]] to i32
// CHECK: store i35 %[[LOADE]], i35* %[[EADDR:.+]]
// CHECK: %[[LOADE2:.+]] = load i35, i35* %[[EADDR]]
// CHECK: %[[CONV:.+]] = trunc i35 %[[LOADE2]] to i32
// CHECK: %[[EXT:.+]] = zext i32 %[[CONV]] to i35
// CHECK: %[[CHECK:.+]] = icmp eq i35 %[[EXT]], %[[LOADE]]
// CHECK: %[[CHECK:.+]] = icmp eq i35 %[[EXT]], %[[LOADE2]]
// CHECK: br i1 %[[CHECK]]
// CHECK: call void @__ubsan_handle_implicit_conversion_abort

Expand All @@ -76,9 +78,11 @@ void IntTruncation(_ExtInt(35) E, unsigned _ExtInt(42) UE, int i, unsigned j) {

j = E;
// CHECK: %[[LOADE:.+]] = load i35
// CHECK: %[[CONV:.+]] = trunc i35 %[[LOADE]] to i32
// CHECK: store i35 %[[LOADE]], i35* %[[EADDR:.+]]
// CHECK: %[[LOADE2:.+]] = load i35, i35* %[[EADDR]]
// CHECK: %[[CONV:.+]] = trunc i35 %[[LOADE2]] to i32
// CHECK: %[[EXT:.+]] = zext i32 %[[CONV]] to i35
// CHECK: %[[CHECK:.+]] = icmp eq i35 %[[EXT]], %[[LOADE]]
// CHECK: %[[CHECK:.+]] = icmp eq i35 %[[EXT]], %[[LOADE2]]
// CHECK: br i1 %[[CHECK]]
// CHECK: call void @__ubsan_handle_implicit_conversion_abort

Expand Down Expand Up @@ -118,16 +122,19 @@ void IntTruncation(_ExtInt(35) E, unsigned _ExtInt(42) UE, int i, unsigned j) {
// CHECK: define void @_Z15SignChangeCheckU7_ExtIntILi39EEjU7_ExtIntILi39EEi
void SignChangeCheck(unsigned _ExtInt(39) UE, _ExtInt(39) E) {
UE = E;
// CHECK: %[[LOADEU:.+]] = load i39
// CHECK: %[[LOADE:.+]] = load i39
// CHECK: %[[NEG:.+]] = icmp slt i39 %[[LOADE]], 0
// CHECK: store i39 %[[LOADE]], i39* %[[EADDR:.+]]
// CHECK: %[[LOADE2:.+]] = load i39, i39* %[[EADDR]]
// CHECK: %[[NEG:.+]] = icmp slt i39 %[[LOADE2]], 0
// CHECK: %[[SIGNCHECK:.+]] = icmp eq i1 %[[NEG]], false
// CHECK: br i1 %[[SIGNCHECK]]
// CHECK: call void @__ubsan_handle_implicit_conversion_abort


E = UE;
// CHECK: %[[LOADUE:.+]] = load i39
// CHECK: %[[NEG:.+]] = icmp slt i39 %[[LOADUE]], 0
// CHECK: store i39 %[[LOADE2]], i39* %[[UEADDR:.+]]
// CHECK: %[[LOADUE2:.+]] = load i39, i39* %[[UEADDR]]
// CHECK: %[[NEG:.+]] = icmp slt i39 %[[LOADUE2]], 0
// CHECK: %[[SIGNCHECK:.+]] = icmp eq i1 false, %[[NEG]]
// CHECK: br i1 %[[SIGNCHECK]]
// CHECK: call void @__ubsan_handle_implicit_conversion_abort
Expand All @@ -138,8 +145,10 @@ void DivByZero(_ExtInt(11) E, int i) {

// Also triggers signed integer overflow.
E / E;
// CHECK: %[[E:.+]] = load i11, i11*
// CHECK: %[[E2:.+]] = load i11, i11*
// CHECK: %[[E1LOAD:.+]] = load i11
// CHECK: store i11 %[[E1LOAD]], i11* %[[EADDR:.+]]
// CHECK: %[[E:.+]] = load i11, i11* %[[EADDR]]
// CHECK: %[[E2:.+]] = load i11, i11* %[[EADDR]]
// CHECK: %[[NEZERO:.+]] = icmp ne i11 %[[E2]], 0
// CHECK: %[[NEMIN:.+]] = icmp ne i11 %[[E]], -1024
// CHECK: %[[NENEG1:.+]] = icmp ne i11 %[[E2]], -1
Expand All @@ -154,8 +163,10 @@ void DivByZero(_ExtInt(11) E, int i) {
// CHECK: define void @_Z6ShiftsU7_ExtIntILi9EEi
void Shifts(_ExtInt(9) E) {
E >> E;
// CHECK: %[[LHSE:.+]] = load i9, i9*
// CHECK: %[[RHSE:.+]] = load i9, i9*
// CHECK: %[[E1LOAD:.+]] = load i9, i9*
// CHECK: store i9 %[[E1LOAD]], i9* %[[EADDR:.+]]
// CHECK: %[[LHSE:.+]] = load i9, i9* %[[EADDR]]
// CHECK: %[[RHSE:.+]] = load i9, i9* %[[EADDR]]
// CHECK: %[[CMP:.+]] = icmp ule i9 %[[RHSE]], 8
// CHECK: br i1 %[[CMP]]
// CHECK: call void @__ubsan_handle_shift_out_of_bounds_abort
Expand All @@ -179,8 +190,10 @@ void SignedIntegerOverflow(_ExtInt(93) BiggestE,
_ExtInt(4) SmallestE,
_ExtInt(31) JustRightE) {
BiggestE + BiggestE;
// CHECK: %[[LOAD1:.+]] = load i93, i93*
// CHECK: %[[LOAD2:.+]] = load i93, i93*
// CHECK: %[[LOADBIGGESTE2:.+]] = load i93
// CHECK: store i93 %[[LOADBIGGESTE2]], i93* %[[BIGGESTEADDR:.+]]
// CHECK: %[[LOAD1:.+]] = load i93, i93* %[[BIGGESTEADDR]]
// CHECK: %[[LOAD2:.+]] = load i93, i93* %[[BIGGESTEADDR]]
// CHECK: %[[OFCALL:.+]] = call { i93, i1 } @llvm.sadd.with.overflow.i93(i93 %[[LOAD1]], i93 %[[LOAD2]])
// CHECK: %[[EXRESULT:.+]] = extractvalue { i93, i1 } %[[OFCALL]], 0
// CHECK: %[[OFRESULT:.+]] = extractvalue { i93, i1 } %[[OFCALL]], 1
Expand Down Expand Up @@ -214,8 +227,10 @@ void UnsignedIntegerOverflow(unsigned u,
unsigned _ExtInt(23) SmallE,
unsigned _ExtInt(35) BigE) {
u = SmallE + SmallE;
// CHECK: %[[LOADE1:.+]] = load i23, i23*
// CHECK: %[[LOADE2:.+]] = load i23, i23*
// CHECK: %[[LOADBIGGESTE2:.+]] = load i23
// CHECK: store i23 %[[LOADBIGGESTE2]], i23* %[[BIGGESTEADDR:.+]]
// CHECK: %[[LOADE1:.+]] = load i23, i23* %[[BIGGESTEADDR]]
// CHECK: %[[LOADE2:.+]] = load i23, i23* %[[BIGGESTEADDR]]
// CHECK: %[[OFCALL:.+]] = call { i23, i1 } @llvm.uadd.with.overflow.i23(i23 %[[LOADE1]], i23 %[[LOADE2]])
// CHECK: %[[EXRESULT:.+]] = extractvalue { i23, i1 } %[[OFCALL]], 0
// CHECK: %[[OFRESULT:.+]] = extractvalue { i23, i1 } %[[OFCALL]], 1
Expand Down
31 changes: 17 additions & 14 deletions clang/test/CodeGen/ext-int.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// RUN: %clang_cc1 -triple x86_64-gnu-linux -O3 -disable-llvm-passes -emit-llvm -o - %s | FileCheck %s --check-prefixes=CHECK
// RUN: %clang_cc1 -triple x86_64-windows-pc -O3 -disable-llvm-passes -emit-llvm -o - %s | FileCheck %s --check-prefixes=CHECK

// RUN: %clang_cc1 -triple x86_64-gnu-linux -O3 -disable-llvm-passes -emit-llvm -o - %s | FileCheck %s --check-prefixes=CHECK,CHECK64
// RUN: %clang_cc1 -triple x86_64-windows-pc -O3 -disable-llvm-passes -emit-llvm -o - %s | FileCheck %s --check-prefixes=CHECK,CHECK64
// RUN: %clang_cc1 -triple i386-gnu-linux -O3 -disable-llvm-passes -emit-llvm -o - %s | FileCheck %s --check-prefixes=CHECK,LIN32
// RUN: %clang_cc1 -triple i386-windows-pc -O3 -disable-llvm-passes -emit-llvm -o - %s | FileCheck %s --check-prefixes=CHECK,WIN32

void GenericTest(_ExtInt(3) a, unsigned _ExtInt(3) b, _ExtInt(4) c) {
// CHECK: define {{.*}}void @GenericTest
Expand All @@ -15,14 +16,14 @@ void GenericTest(_ExtInt(3) a, unsigned _ExtInt(3) b, _ExtInt(4) c) {
void VLATest(_ExtInt(3) A, _ExtInt(99) B, _ExtInt(123456) C) {
// CHECK: define {{.*}}void @VLATest
int AR1[A];
// CHECK: %[[A:.+]] = zext i3 %{{.+}} to i64
// CHECK: %[[VLA1:.+]] = alloca i32, i64 %[[A]]
// CHECK: %[[A:.+]] = zext i3 %{{.+}} to i[[INDXSIZE:[0-9]+]]
// CHECK: %[[VLA1:.+]] = alloca i32, i[[INDXSIZE]] %[[A]]
int AR2[B];
// CHECK: %[[B:.+]] = trunc i99 %{{.+}} to i64
// CHECK: %[[VLA2:.+]] = alloca i32, i64 %[[B]]
// CHECK: %[[B:.+]] = trunc i99 %{{.+}} to i[[INDXSIZE]]
// CHECK: %[[VLA2:.+]] = alloca i32, i[[INDXSIZE]] %[[B]]
int AR3[C];
// CHECK: %[[C:.+]] = trunc i123456 %{{.+}} to i64
// CHECK: %[[VLA3:.+]] = alloca i32, i64 %[[C]]
// CHECK: %[[C:.+]] = trunc i123456 %{{.+}} to i[[INDXSIZE]]
// CHECK: %[[VLA3:.+]] = alloca i32, i[[INDXSIZE]] %[[C]]
}

struct S {
Expand All @@ -32,13 +33,15 @@ struct S {
};

void OffsetOfTest() {
// CHECK: define {{.*}}void @OffsetOfTest
// CHECK: define {{.*}}void @OffsetOfTest
int A = __builtin_offsetof(struct S,A);
// CHECK: store i32 0, i32* %{{.+}}
int B = __builtin_offsetof(struct S,B);
// CHECK: store i32 8, i32* %{{.+}}
// CHECK64: store i32 8, i32* %{{.+}}
// LIN32: store i32 4, i32* %{{.+}}
// WINCHECK32: store i32 8, i32* %{{.+}}
int C = __builtin_offsetof(struct S,C);
// CHECK: store i32 2097160, i32* %{{.+}}
// CHECK64: store i32 2097160, i32* %{{.+}}
// LIN32: store i32 2097156, i32* %{{.+}}
// WIN32: store i32 2097160, i32* %{{.+}}
}


Loading

0 comments on commit 65be4e0

Please sign in to comment.