Skip to content

Commit a01f70e

Browse files
SC llvm teamSC llvm team
authored andcommitted
Merged main:f88f090a2ef1 into amd-gfx:4e956125f560
Local branch amd-gfx 4e95612 Merged main:d89d3a6a0eb3 into amd-gfx:6b554b98f849 Remote branch main f88f090 [libc] Correct memrchr definition and re-enable on GPU (llvm#67850)
2 parents 4e95612 + f88f090 commit a01f70e

File tree

37 files changed

+606
-486
lines changed

37 files changed

+606
-486
lines changed

clang/lib/CodeGen/CGExpr.cpp

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,12 @@
5151
using namespace clang;
5252
using namespace CodeGen;
5353

54+
// Experiment to make sanitizers easier to debug
55+
static llvm::cl::opt<bool> ClSanitizeDebugDeoptimization(
56+
"ubsan-unique-traps", llvm::cl::Optional,
57+
llvm::cl::desc("Deoptimize traps for UBSAN so there is 1 trap per check"),
58+
llvm::cl::init(false));
59+
5460
//===--------------------------------------------------------------------===//
5561
// Miscellaneous Helper Methods
5662
//===--------------------------------------------------------------------===//
@@ -3553,17 +3559,28 @@ void CodeGenFunction::EmitTrapCheck(llvm::Value *Checked,
35533559
// check-type per function to save on code size.
35543560
if (TrapBBs.size() <= CheckHandlerID)
35553561
TrapBBs.resize(CheckHandlerID + 1);
3562+
35563563
llvm::BasicBlock *&TrapBB = TrapBBs[CheckHandlerID];
35573564

3558-
if (!CGM.getCodeGenOpts().OptimizationLevel || !TrapBB ||
3559-
(CurCodeDecl && CurCodeDecl->hasAttr<OptimizeNoneAttr>())) {
3565+
if (!ClSanitizeDebugDeoptimization &&
3566+
CGM.getCodeGenOpts().OptimizationLevel && TrapBB &&
3567+
(!CurCodeDecl || !CurCodeDecl->hasAttr<OptimizeNoneAttr>())) {
3568+
auto Call = TrapBB->begin();
3569+
assert(isa<llvm::CallInst>(Call) && "Expected call in trap BB");
3570+
3571+
Call->applyMergedLocation(Call->getDebugLoc(),
3572+
Builder.getCurrentDebugLocation());
3573+
Builder.CreateCondBr(Checked, Cont, TrapBB);
3574+
} else {
35603575
TrapBB = createBasicBlock("trap");
35613576
Builder.CreateCondBr(Checked, Cont, TrapBB);
35623577
EmitBlock(TrapBB);
35633578

3564-
llvm::CallInst *TrapCall =
3565-
Builder.CreateCall(CGM.getIntrinsic(llvm::Intrinsic::ubsantrap),
3566-
llvm::ConstantInt::get(CGM.Int8Ty, CheckHandlerID));
3579+
llvm::CallInst *TrapCall = Builder.CreateCall(
3580+
CGM.getIntrinsic(llvm::Intrinsic::ubsantrap),
3581+
llvm::ConstantInt::get(CGM.Int8Ty, ClSanitizeDebugDeoptimization
3582+
? TrapBB->getParent()->size()
3583+
: CheckHandlerID));
35673584

35683585
if (!CGM.getCodeGenOpts().TrapFuncName.empty()) {
35693586
auto A = llvm::Attribute::get(getLLVMContext(), "trap-func-name",
@@ -3573,13 +3590,6 @@ void CodeGenFunction::EmitTrapCheck(llvm::Value *Checked,
35733590
TrapCall->setDoesNotReturn();
35743591
TrapCall->setDoesNotThrow();
35753592
Builder.CreateUnreachable();
3576-
} else {
3577-
auto Call = TrapBB->begin();
3578-
assert(isa<llvm::CallInst>(Call) && "Expected call in trap BB");
3579-
3580-
Call->applyMergedLocation(Call->getDebugLoc(),
3581-
Builder.getCurrentDebugLocation());
3582-
Builder.CreateCondBr(Checked, Cont, TrapBB);
35833593
}
35843594

35853595
EmitBlock(Cont);

clang/lib/Headers/llvm_libc_wrappers/time.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525

2626
_Static_assert(sizeof(clock_t) == sizeof(long), "ABI mismatch!");
2727

28-
#include <llvm-libc-decls/ctype.h>
28+
#include <llvm-libc-decls/time.h>
2929

3030
#pragma omp end declare target
3131

clang/test/CodeGen/bounds-checking.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
// RUN: %clang_cc1 -fsanitize=local-bounds -emit-llvm -triple x86_64-apple-darwin10 %s -o - | FileCheck %s
22
// RUN: %clang_cc1 -fsanitize=array-bounds -O -fsanitize-trap=array-bounds -emit-llvm -triple x86_64-apple-darwin10 -DNO_DYNAMIC %s -o - | FileCheck %s
3+
// RUN: %clang_cc1 -fsanitize=local-bounds -fsanitize-trap=local-bounds -O3 -mllvm -bounds-checking-unique-traps -emit-llvm -triple x86_64-apple-darwin10 %s -o - | FileCheck %s --check-prefixes=NOOPTLOCAL
4+
// RUN: %clang_cc1 -fsanitize=array-bounds -fsanitize-trap=array-bounds -O3 -mllvm -ubsan-unique-traps -emit-llvm -triple x86_64-apple-darwin10 %s -o - | FileCheck %s --check-prefixes=NOOPTARRAY
35
//
46
// REQUIRES: x86-registered-target
57

@@ -66,3 +68,17 @@ int f7(union U *u, int i) {
6668
// CHECK-NOT: @llvm.ubsantrap
6769
return u->c[i];
6870
}
71+
72+
73+
char B[10];
74+
char B2[10];
75+
// CHECK-LABEL: @f8
76+
void f8(int i, int k) {
77+
// NOOPTLOCAL: call void @llvm.ubsantrap(i8 3)
78+
// NOOPTARRAY: call void @llvm.ubsantrap(i8 2)
79+
B[i] = '\0';
80+
81+
// NOOPTLOCAL: call void @llvm.ubsantrap(i8 5)
82+
// NOOPTARRAY: call void @llvm.ubsantrap(i8 4)
83+
B2[k] = '\0';
84+
}

clang/test/Driver/ve-toolchain.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
/// Checking include-path
1414

1515
// RUN: %clangxx -### --target=ve-unknown-linux-gnu \
16-
// RUN: --sysroot %S/Inputs/basic_ve_tree %s \
16+
// RUN: --sysroot %S/Inputs/basic_ve_tree %s -fuse-ld=ld \
1717
// RUN: -ccc-install-dir %S/Inputs/basic_ve_tree/bin \
1818
// RUN: -resource-dir=%S/Inputs/basic_ve_tree/resource_dir \
1919
// RUN: 2>&1 | FileCheck -check-prefix=DEFINC %s

compiler-rt/lib/hwasan/hwasan_interceptors.cpp

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,21 @@
3131

3232
using namespace __hwasan;
3333

34+
struct HWAsanInterceptorContext {
35+
const char *interceptor_name;
36+
};
37+
38+
# define ACCESS_MEMORY_RANGE(ctx, offset, size, access) \
39+
do { \
40+
__hwasan::CheckAddressSized<ErrorAction::Abort, access>((uptr)offset, \
41+
size); \
42+
} while (0)
43+
44+
# define HWASAN_READ_RANGE(ctx, offset, size) \
45+
ACCESS_MEMORY_RANGE(ctx, offset, size, AccessType::Load)
46+
# define HWASAN_WRITE_RANGE(ctx, offset, size) \
47+
ACCESS_MEMORY_RANGE(ctx, offset, size, AccessType::Store)
48+
3449
# if !SANITIZER_APPLE
3550
# define HWASAN_INTERCEPT_FUNC(name) \
3651
do { \
@@ -79,13 +94,11 @@ using namespace __hwasan;
7994
} while (false)
8095

8196
# define COMMON_INTERCEPTOR_READ_RANGE(ctx, ptr, size) \
82-
do { \
83-
(void)(ctx); \
84-
(void)(ptr); \
85-
(void)(size); \
86-
} while (false)
97+
HWASAN_READ_RANGE(ctx, ptr, size)
8798

8899
# define COMMON_INTERCEPTOR_ENTER(ctx, func, ...) \
100+
HWAsanInterceptorContext _ctx = {#func}; \
101+
ctx = (void *)&_ctx; \
89102
do { \
90103
(void)(ctx); \
91104
(void)(func); \

compiler-rt/lib/hwasan/hwasan_platform_interceptors.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,8 @@
6565
#undef SANITIZER_INTERCEPT_MEMCPY
6666
#define SANITIZER_INTERCEPT_MEMCPY 0
6767

68-
#undef SANITIZER_INTERCEPT_MEMCMP
69-
#define SANITIZER_INTERCEPT_MEMCMP 0
68+
// #undef SANITIZER_INTERCEPT_MEMCMP
69+
// #define SANITIZER_INTERCEPT_MEMCMP 0
7070

7171
#undef SANITIZER_INTERCEPT_BCMP
7272
#define SANITIZER_INTERCEPT_BCMP 0

compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -445,11 +445,13 @@ INTERCEPTOR(char*, textdomain, const char *domainname) {
445445
#define INIT_TEXTDOMAIN
446446
#endif
447447

448-
#if SANITIZER_INTERCEPT_STRCMP
448+
#if SANITIZER_INTERCEPT_STRCMP || SANITIZER_INTERCEPT_MEMCMP
449449
static inline int CharCmpX(unsigned char c1, unsigned char c2) {
450450
return (c1 == c2) ? 0 : (c1 < c2) ? -1 : 1;
451451
}
452+
#endif
452453

454+
#if SANITIZER_INTERCEPT_STRCMP
453455
DECLARE_WEAK_INTERCEPTOR_HOOK(__sanitizer_weak_hook_strcmp, uptr called_pc,
454456
const char *s1, const char *s2, int result)
455457

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// RUN: %clangxx_hwasan -O0 %s -o %t && not %run %t 2>&1 | FileCheck %s
2+
// RUN: %clangxx_hwasan -O1 %s -o %t && not %run %t 2>&1 | FileCheck %s
3+
// RUN: %clangxx_hwasan -O2 %s -o %t && not %run %t 2>&1 | FileCheck %s
4+
// RUN: %clangxx_hwasan -O3 %s -o %t && not %run %t 2>&1 | FileCheck %s
5+
6+
#include <sanitizer/hwasan_interface.h>
7+
#include <stdlib.h>
8+
#include <string.h>
9+
#include <unistd.h>
10+
11+
int main(int argc, char **argv) {
12+
__hwasan_enable_allocator_tagging();
13+
char a[] = {static_cast<char>(argc), 2, 3, 4};
14+
volatile int size = sizeof(a);
15+
char *volatile p = (char *)malloc(size);
16+
memcpy(p, a, size);
17+
free(p);
18+
return memcmp(p, a, size);
19+
// CHECK: HWAddressSanitizer: tag-mismatch on address
20+
// CHECK: READ of size 4
21+
// CHECK: #{{[[:digit:]]+}} 0x{{[[:xdigit:]]+}} in main {{.*}}memcmp.cpp:[[@LINE-3]]
22+
// CHECK: Cause: use-after-free
23+
// CHECK: freed by thread
24+
// CHECK: #{{[[:digit:]]+}} 0x{{[[:xdigit:]]+}} in main {{.*}}memcmp.cpp:[[@LINE-7]]
25+
// CHECK: previously allocated by thread
26+
// CHECK: #{{[[:digit:]]+}} 0x{{[[:xdigit:]]+}} in main {{.*}}memcmp.cpp:[[@LINE-11]]
27+
}

libc/spec/gnu_ext.td

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ def GnuExtensions : StandardSpec<"GNUExtensions"> {
6969
FunctionSpec<
7070
"memrchr",
7171
RetValSpec<VoidPtr>,
72-
[ArgSpec<VoidPtr>, ArgSpec<IntType>, ArgSpec<SizeTType>]
72+
[ArgSpec<ConstVoidPtr>, ArgSpec<IntType>, ArgSpec<SizeTType>]
7373
>,
7474
FunctionSpec<
7575
"strerror_r",

libc/spec/posix.td

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ def ConstStructDirentPtrPtr : ConstType<StructDirentPtrPtr>;
4444

4545
def StructTimeSpec : NamedType<"struct timespec">;
4646
def StructTimeSpecPtr : PtrType<StructTimeSpec>;
47+
def ConstStructTimeSpecPtr : ConstType<StructTimeSpecPtr>;
4748

4849
def StructSchedParam : NamedType<"struct sched_param">;
4950
def StructSchedParamPtr : PtrType<StructSchedParam>;
@@ -1192,7 +1193,7 @@ def POSIX : StandardSpec<"POSIX"> {
11921193
FunctionSpec<
11931194
"nanosleep",
11941195
RetValSpec<IntType>,
1195-
[ArgSpec<StructTimeSpecPtr>, ArgSpec<StructTimeSpecPtr>]
1196+
[ArgSpec<ConstStructTimeSpecPtr>, ArgSpec<StructTimeSpecPtr>]
11961197
>,
11971198
]
11981199
>;

libunwind/src/FrameHeaderCache.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@
3131

3232
class _LIBUNWIND_HIDDEN FrameHeaderCache {
3333
struct CacheEntry {
34-
uintptr_t LowPC() { return Info.dso_base; };
35-
uintptr_t HighPC() { return Info.dso_base + Info.text_segment_length; };
34+
uintptr_t LowPC() { return Info.dso_base; }
35+
uintptr_t HighPC() { return Info.dso_base + Info.text_segment_length; }
3636
UnwindInfoSections Info;
3737
CacheEntry *Next;
3838
};

llvm/include/llvm/CodeGen/BasicTTIImpl.h

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -935,28 +935,31 @@ class BasicTTIImplBase : public TargetTransformInfoImplCRTPBase<T> {
935935
ArrayRef<int> Mask,
936936
VectorType *Ty, int &Index,
937937
VectorType *&SubTy) const {
938-
if (Mask.empty())
938+
int Limit = Mask.size() * 2;
939+
if (Mask.empty() ||
940+
// Extra check required by isSingleSourceMaskImpl function (called by
941+
// ShuffleVectorInst::isSingleSourceMask).
942+
any_of(Mask, [Limit](int I) { return I >= Limit; }))
939943
return Kind;
940-
int NumSrcElts = Ty->getElementCount().getKnownMinValue();
941944
switch (Kind) {
942945
case TTI::SK_PermuteSingleSrc:
943-
if (ShuffleVectorInst::isReverseMask(Mask, NumSrcElts))
946+
if (ShuffleVectorInst::isReverseMask(Mask))
944947
return TTI::SK_Reverse;
945-
if (ShuffleVectorInst::isZeroEltSplatMask(Mask, NumSrcElts))
948+
if (ShuffleVectorInst::isZeroEltSplatMask(Mask))
946949
return TTI::SK_Broadcast;
947950
break;
948951
case TTI::SK_PermuteTwoSrc: {
949952
int NumSubElts;
950953
if (Mask.size() > 2 && ShuffleVectorInst::isInsertSubvectorMask(
951-
Mask, NumSrcElts, NumSubElts, Index)) {
954+
Mask, Mask.size(), NumSubElts, Index)) {
952955
SubTy = FixedVectorType::get(Ty->getElementType(), NumSubElts);
953956
return TTI::SK_InsertSubvector;
954957
}
955-
if (ShuffleVectorInst::isSelectMask(Mask, NumSrcElts))
958+
if (ShuffleVectorInst::isSelectMask(Mask))
956959
return TTI::SK_Select;
957-
if (ShuffleVectorInst::isTransposeMask(Mask, NumSrcElts))
960+
if (ShuffleVectorInst::isTransposeMask(Mask))
958961
return TTI::SK_Transpose;
959-
if (ShuffleVectorInst::isSpliceMask(Mask, NumSrcElts, Index))
962+
if (ShuffleVectorInst::isSpliceMask(Mask, Index))
960963
return TTI::SK_Splice;
961964
break;
962965
}

llvm/include/llvm/Config/llvm-config.h.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
/* Indicate that this is LLVM compiled from the amd-gfx branch. */
1818
#define LLVM_HAVE_BRANCH_AMD_GFX
19-
#define LLVM_MAIN_REVISION 476421
19+
#define LLVM_MAIN_REVISION 476431
2020

2121
/* Define if LLVM_ENABLE_DUMP is enabled */
2222
#cmakedefine LLVM_ENABLE_DUMP

0 commit comments

Comments
 (0)