Skip to content

Commit 1c8a52e

Browse files
authored
merge main into amd-staging (llvm#1821)
2 parents c0cbcad + d140c89 commit 1c8a52e

File tree

38 files changed

+2311
-72
lines changed

38 files changed

+2311
-72
lines changed

clang/lib/AST/ExprConstant.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2232,10 +2232,15 @@ static bool ArePotentiallyOverlappingStringLiterals(const EvalInfo &Info,
22322232
// within RHS. We don't need to look at the characters of one string that
22332233
// would appear before the start of the other string if they were merged.
22342234
CharUnits Offset = RHS.Offset - LHS.Offset;
2235-
if (Offset.isNegative())
2235+
if (Offset.isNegative()) {
2236+
if (LHSString.Bytes.size() < (size_t)-Offset.getQuantity())
2237+
return false;
22362238
LHSString.Bytes = LHSString.Bytes.drop_front(-Offset.getQuantity());
2237-
else
2239+
} else {
2240+
if (RHSString.Bytes.size() < (size_t)Offset.getQuantity())
2241+
return false;
22382242
RHSString.Bytes = RHSString.Bytes.drop_front(Offset.getQuantity());
2243+
}
22392244

22402245
bool LHSIsLonger = LHSString.Bytes.size() > RHSString.Bytes.size();
22412246
StringRef Longer = LHSIsLonger ? LHSString.Bytes : RHSString.Bytes;

clang/lib/CodeGen/CGClass.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2899,7 +2899,8 @@ void CodeGenFunction::EmitVTablePtrCheck(const CXXRecordDecl *RD,
28992899
}
29002900

29012901
if (CGM.getCodeGenOpts().SanitizeTrap.has(M)) {
2902-
EmitTrapCheck(TypeTest, SanitizerHandler::CFICheckFail);
2902+
bool NoMerge = !CGM.getCodeGenOpts().SanitizeMergeHandlers.has(M);
2903+
EmitTrapCheck(TypeTest, SanitizerHandler::CFICheckFail, NoMerge);
29032904
return;
29042905
}
29052906

clang/lib/CodeGen/CGExpr.cpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3927,7 +3927,11 @@ void CodeGenFunction::EmitCfiCheckFail() {
39273927
// Data == nullptr means the calling module has trap behaviour for this check.
39283928
llvm::Value *DataIsNotNullPtr =
39293929
Builder.CreateICmpNE(Data, llvm::ConstantPointerNull::get(Int8PtrTy));
3930-
EmitTrapCheck(DataIsNotNullPtr, SanitizerHandler::CFICheckFail);
3930+
// TODO: since there is no data, we don't know the CheckKind, and therefore
3931+
// cannot inspect CGM.getCodeGenOpts().SanitizeMergeHandlers. We default to
3932+
// NoMerge = false. Users can disable merging by disabling optimization.
3933+
EmitTrapCheck(DataIsNotNullPtr, SanitizerHandler::CFICheckFail,
3934+
/*NoMerge=*/false);
39313935

39323936
llvm::StructType *SourceLocationTy =
39333937
llvm::StructType::get(VoidPtrTy, Int32Ty, Int32Ty);
@@ -3966,7 +3970,11 @@ void CodeGenFunction::EmitCfiCheckFail() {
39663970
EmitCheck(std::make_pair(Cond, Ordinal), SanitizerHandler::CFICheckFail,
39673971
{}, {Data, Addr, ValidVtable});
39683972
else
3969-
EmitTrapCheck(Cond, SanitizerHandler::CFICheckFail);
3973+
// TODO: we can't rely on CGM.getCodeGenOpts().SanitizeMergeHandlers.
3974+
// Although the compiler allows SanitizeMergeHandlers to be set
3975+
// independently of CGM.getLangOpts().Sanitize, Driver/SanitizerArgs.cpp
3976+
// requires that SanitizeMergeHandlers is a subset of Sanitize.
3977+
EmitTrapCheck(Cond, SanitizerHandler::CFICheckFail, /*NoMerge=*/false);
39703978
}
39713979

39723980
FinishFunction();

clang/lib/Driver/SanitizerArgs.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -853,8 +853,8 @@ SanitizerArgs::SanitizerArgs(const ToolChain &TC,
853853
SanitizerMask NonTrappingCfi = Kinds & SanitizerKind::CFI & ~TrappingKinds;
854854
if (NonTrappingCfi && DiagnoseErrors)
855855
D.Diag(clang::diag::err_drv_argument_only_allowed_with)
856-
<< "fsanitize-minimal-runtime"
857-
<< "fsanitize-trap=cfi";
856+
<< "-fsanitize-minimal-runtime"
857+
<< "-fsanitize-trap=cfi";
858858
}
859859

860860
for (const auto *Arg : Args.filtered(

clang/lib/Serialization/ASTReaderDecl.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1076,6 +1076,8 @@ void ASTDeclReader::VisitFunctionDecl(FunctionDecl *FD) {
10761076
FD->setFriendConstraintRefersToEnclosingTemplate(
10771077
FunctionDeclBits.getNextBit());
10781078
FD->setUsesSEHTry(FunctionDeclBits.getNextBit());
1079+
FD->setIsDestroyingOperatorDelete(FunctionDeclBits.getNextBit());
1080+
FD->setIsTypeAwareOperatorNewOrDelete(FunctionDeclBits.getNextBit());
10791081

10801082
FD->EndRangeLoc = readSourceLocation();
10811083
if (FD->isExplicitlyDefaulted())

clang/lib/Serialization/ASTWriterDecl.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -847,6 +847,8 @@ void ASTDeclWriter::VisitFunctionDecl(FunctionDecl *D) {
847847
FunctionDeclBits.addBit(D->isInstantiatedFromMemberTemplate());
848848
FunctionDeclBits.addBit(D->FriendConstraintRefersToEnclosingTemplate());
849849
FunctionDeclBits.addBit(D->usesSEHTry());
850+
FunctionDeclBits.addBit(D->isDestroyingOperatorDelete());
851+
FunctionDeclBits.addBit(D->isTypeAwareOperatorNewOrDelete());
850852
Record.push_back(FunctionDeclBits);
851853

852854
Record.AddSourceLocation(D->getEndLoc());

clang/test/AST/ByteCode/cxx20.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,14 @@ constexpr auto b3 = name1() == name1(); // ref-error {{must be initialized by a
119119
constexpr auto b4 = name1() == name2();
120120
static_assert(!b4);
121121

122+
constexpr auto bar(const char *p) { return p + __builtin_strlen(p); }
123+
constexpr auto b5 = bar(p1) == p1;
124+
static_assert(!b5);
125+
constexpr auto b6 = bar(p1) == ""; // ref-error {{must be initialized by a constant expression}} \
126+
// ref-note {{comparison of addresses of potentially overlapping literals}}
127+
constexpr auto b7 = bar(p1) + 1 == ""; // both-error {{must be initialized by a constant expression}} \
128+
// both-note {{comparison against pointer '&"test1"[6]' that points past the end of a complete object has unspecified value}}
129+
122130
namespace UninitializedFields {
123131
class A {
124132
public:

clang/test/Driver/fsanitize.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -962,18 +962,18 @@
962962
// CHECK-CFI-ABORT-MINIMAL: "-fsanitize-minimal-runtime"
963963

964964
// RUN: not %clang --target=x86_64-linux-gnu -fsanitize=cfi -flto -fvisibility=hidden -fsanitize-minimal-runtime -fno-sanitize-trap=cfi -fsanitize-recover=cfi -resource-dir=%S/Inputs/resource_dir %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-CFI-NOTRAP-RECOVER-MINIMAL --
965-
// CHECK-CFI-NOTRAP-RECOVER-MINIMAL: 'fsanitize-minimal-runtime' only allowed with 'fsanitize-trap=cfi'
965+
// CHECK-CFI-NOTRAP-RECOVER-MINIMAL: '-fsanitize-minimal-runtime' only allowed with '-fsanitize-trap=cfi'
966966
// CHECK-CFI-NOTRAP-RECOVER-MINIMAL: "-fsanitize=cfi-derived-cast,cfi-icall,cfi-mfcall,cfi-unrelated-cast,cfi-nvcall,cfi-vcall"
967967
// CHECK-CFI-NOTRAP-RECOVER-MINIMAL: "-fsanitize-recover=cfi-derived-cast,cfi-icall,cfi-mfcall,cfi-unrelated-cast,cfi-nvcall,cfi-vcall"
968968
// CHECK-CFI-NOTRAP-RECOVER-MINIMAL: "-fsanitize-minimal-runtime"
969969

970970
// RUN: not %clang --target=x86_64-linux-gnu -fsanitize=cfi -flto -fvisibility=hidden -fsanitize-minimal-runtime -fno-sanitize-trap=cfi -fno-sanitize-recover=cfi -resource-dir=%S/Inputs/resource_dir %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-CFI-NOTRAP-ABORT-MINIMAL
971-
// CHECK-CFI-NOTRAP-ABORT-MINIMAL: 'fsanitize-minimal-runtime' only allowed with 'fsanitize-trap=cfi'
971+
// CHECK-CFI-NOTRAP-ABORT-MINIMAL: '-fsanitize-minimal-runtime' only allowed with '-fsanitize-trap=cfi'
972972
// CHECK-CFI-NOTRAP-ABORT-MINIMAL: "-fsanitize=cfi-derived-cast,cfi-icall,cfi-mfcall,cfi-unrelated-cast,cfi-nvcall,cfi-vcall"
973973
// CHECK-CFI-NOTRAP-ABORT-MINIMAL: "-fsanitize-minimal-runtime"
974974

975975
// RUN: not %clang --target=x86_64-linux-gnu -fsanitize=cfi -fno-sanitize-trap=cfi-icall -flto -fvisibility=hidden -fsanitize-minimal-runtime %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-CFI-NOTRAP-MINIMAL
976-
// CHECK-CFI-NOTRAP-MINIMAL: error: invalid argument 'fsanitize-minimal-runtime' only allowed with 'fsanitize-trap=cfi'
976+
// CHECK-CFI-NOTRAP-MINIMAL: error: invalid argument '-fsanitize-minimal-runtime' only allowed with '-fsanitize-trap=cfi'
977977

978978
// RUN: %clang --target=x86_64-linux-gnu -fsanitize=cfi -fno-sanitize-trap=cfi-icall -fno-sanitize=cfi-icall -flto -fvisibility=hidden -fsanitize-minimal-runtime -resource-dir=%S/Inputs/resource_dir %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-CFI-NOICALL-MINIMAL
979979
// CHECK-CFI-NOICALL-MINIMAL: "-fsanitize=cfi-derived-cast,cfi-mfcall,cfi-unrelated-cast,cfi-nvcall,cfi-vcall"

clang/test/Driver/sanitizer-ld.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -928,7 +928,7 @@
928928
// RUN: --sysroot=%S/Inputs/basic_linux_tree \
929929
// RUN: -### %s 2>&1 \
930930
// RUN: | %{filecheck} --check-prefix=CHECK-CFI-MINRT-DIAG-LINUX
931-
// CHECK-CFI-MINRT-DIAG-LINUX: 'fsanitize-minimal-runtime' only allowed with 'fsanitize-trap=cfi'
931+
// CHECK-CFI-MINRT-DIAG-LINUX: '-fsanitize-minimal-runtime' only allowed with '-fsanitize-trap=cfi'
932932
// CHECK-CFI-MINRT-DIAG-LINUX: "{{.*}}ld{{(.exe)?}}"
933933
// CHECK-CFI-MINRT-DIAG-LINUX: "--whole-archive" "{{[^"]*}}libclang_rt.ubsan_minimal.a" "--no-whole-archive"
934934

@@ -955,7 +955,7 @@
955955
// RUN: --sysroot=%S/Inputs/basic_linux_tree \
956956
// RUN: -### %s 2>&1 \
957957
// RUN: | %{filecheck} --check-prefix=CHECK-CFI-MINRT-CROSS-DSO-DIAG-LINUX
958-
// CHECK-CFI-MINRT-CROSS-DSO-DIAG-LINUX: 'fsanitize-minimal-runtime' only allowed with 'fsanitize-trap=cfi'
958+
// CHECK-CFI-MINRT-CROSS-DSO-DIAG-LINUX: '-fsanitize-minimal-runtime' only allowed with '-fsanitize-trap=cfi'
959959
// CHECK-CFI-MINRT-CROSS-DSO-DIAG-LINUX: "{{.*}}ld{{(.exe)?}}"
960960
// CHECK-CFI-MINRT-CROSS-DSO-DIAG-LINUX: "--whole-archive" "{{[^"]*}}libclang_rt.cfi_diag.a" "--no-whole-archive"
961961
// CHECK-CFI-MINRT-CROSS-DSO-DIAG-LINUX: -export-dynamic
@@ -981,7 +981,7 @@
981981
// RUN: --sysroot=%S/Inputs/basic_android_tree \
982982
// RUN: -### %s 2>&1 \
983983
// RUN: | %{filecheck} --check-prefix=CHECK-CFI-MINRT-CROSS-DSO-DIAG-ANDROID
984-
// CHECK-CFI-MINRT-CROSS-DSO-DIAG-ANDROID: 'fsanitize-minimal-runtime' only allowed with 'fsanitize-trap=cfi'
984+
// CHECK-CFI-MINRT-CROSS-DSO-DIAG-ANDROID: '-fsanitize-minimal-runtime' only allowed with '-fsanitize-trap=cfi'
985985
// CHECK-CFI-MINRT-CROSS-DSO-DIAG-ANDROID: "{{.*}}ld{{(.exe)?}}"
986986
// CHECK-CFI-MINRT-CROSS-DSO-DIAG-ANDROID: "{{[^"]*}}libclang_rt.ubsan_minimal.so"
987987
// CHECK-CFI-MINRT-CROSS-DSO-DIAG-ANDROID: "--export-dynamic-symbol=__cfi_check"

clang/test/Format/lit.local.cfg

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ config.suffixes = [
2121
".textpb",
2222
".asciipb",
2323
".td",
24-
".test"
24+
".test",
2525
]
2626

2727
# AIX 'diff' command doesn't support --strip-trailing-cr, but the internal
@@ -31,5 +31,5 @@ if platform.system() == "AIX":
3131

3232
# Create an empty .clang-format-ignore file so that tests don't get messed
3333
# up if one exists higher in the tree
34-
with open(".clang-format-ignore", 'w'):
34+
with open(".clang-format-ignore", "w"):
3535
pass
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module type_aware_destroying_new_delete { header "type_aware_destroying_new_delete.h" export * }
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
2+
namespace std {
3+
struct destroying_delete_t { };
4+
template <class T> struct type_identity {
5+
using type = T;
6+
};
7+
typedef __SIZE_TYPE__ size_t;
8+
enum class align_val_t : size_t;
9+
};
10+
11+
struct A {
12+
A();
13+
void *operator new(std::size_t);
14+
void operator delete(A*, std::destroying_delete_t);
15+
};
16+
17+
struct B {
18+
B();
19+
void *operator new(std::type_identity<B>, std::size_t, std::align_val_t);
20+
void operator delete(std::type_identity<B>, void*, std::size_t, std::align_val_t);
21+
};
22+
23+
struct C {
24+
C();
25+
template <class T> void *operator new(std::type_identity<T>, std::size_t, std::align_val_t);
26+
template <class T> void operator delete(std::type_identity<T>, void*, std::size_t, std::align_val_t);
27+
};
28+
29+
struct D {
30+
D();
31+
};
32+
void *operator new(std::type_identity<D>, std::size_t, std::align_val_t);
33+
void operator delete(std::type_identity<D>, void*, std::size_t, std::align_val_t);
34+
35+
struct E {
36+
E();
37+
};
38+
template <class T> void *operator new(std::type_identity<T>, std::size_t, std::align_val_t);
39+
template <class T> void operator delete(std::type_identity<T>, void*, std::size_t, std::align_val_t);
40+
41+
void in_module_tests() {
42+
A* a = new A;
43+
delete a;
44+
B *b = new B;
45+
delete b;
46+
C *c = new C;
47+
delete c;
48+
D *d = new D;
49+
delete d;
50+
E *e = new E;
51+
delete e;
52+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// RUN: rm -rf %t
2+
// RUN: %clang_cc1 -fmodules -fimplicit-module-maps -x c++ -std=c++26 -fmodules-cache-path=%t -I %S/Inputs/PR137102 -emit-llvm-only %s
3+
// RUN: %clang_cc1 -fmodules -fimplicit-module-maps -x c++ -std=c++26 -fmodules-cache-path=%t -I %S/Inputs/PR137102 -emit-llvm-only %s -triple i686-windows
4+
5+
#include "type_aware_destroying_new_delete.h"
6+
7+
8+
static void call_in_module_function(void) {
9+
in_module_tests();
10+
}
11+
12+
void out_of_module_tests() {
13+
A* a = new A;
14+
delete a;
15+
B *b = new B;
16+
delete b;
17+
C *c = new C;
18+
delete c;
19+
D *d = new D;
20+
delete d;
21+
E *e = new E;
22+
delete e;
23+
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
2+
namespace std {
3+
struct destroying_delete_t { };
4+
template <class T> struct type_identity {
5+
using type = T;
6+
};
7+
typedef __SIZE_TYPE__ size_t;
8+
enum class align_val_t : size_t;
9+
};
10+
11+
struct A {
12+
A();
13+
void *operator new(std::size_t);
14+
void operator delete(A*, std::destroying_delete_t);
15+
};
16+
17+
struct B {
18+
B();
19+
void *operator new(std::type_identity<B>, std::size_t, std::align_val_t);
20+
void operator delete(std::type_identity<B>, void*, std::size_t, std::align_val_t);
21+
};
22+
23+
struct C {
24+
C();
25+
template <class T> void *operator new(std::type_identity<T>, std::size_t, std::align_val_t);
26+
template <class T> void operator delete(std::type_identity<T>, void*, std::size_t, std::align_val_t);
27+
};
28+
29+
struct D {
30+
D();
31+
};
32+
void *operator new(std::type_identity<D>, std::size_t, std::align_val_t);
33+
void operator delete(std::type_identity<D>, void*, std::size_t, std::align_val_t);
34+
35+
struct E {
36+
E();
37+
};
38+
template <class T> void *operator new(std::type_identity<T>, std::size_t, std::align_val_t);
39+
template <class T> void operator delete(std::type_identity<T>, void*, std::size_t, std::align_val_t);
40+
41+
void in_pch_tests() {
42+
A* a = new A;
43+
delete a;
44+
B *b = new B;
45+
delete b;
46+
C *c = new C;
47+
delete c;
48+
D *d = new D;
49+
delete d;
50+
E *e = new E;
51+
delete e;
52+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// Test this without pch.
2+
// RUN: %clang_cc1 -x c++ -std=c++26 -include %S/Inputs/type_aware_destroying_new_delete.h -emit-llvm -o - %s
3+
4+
// Test with pch.
5+
// RUN: %clang_cc1 -x c++ -std=c++26 -emit-pch -o %t %S/Inputs/type_aware_destroying_new_delete.h
6+
// RUN: %clang_cc1 -x c++ -std=c++26 -include-pch %t -emit-llvm -o - %s
7+
8+
// RUN: %clang_cc1 -x c++ -std=c++11 -emit-pch -fpch-instantiate-templates -o %t %S/Inputs/type_aware_destroying_new_delete.h
9+
// RUN: %clang_cc1 -x c++ -std=c++11 -include-pch %t -emit-llvm -o - %s
10+
11+
12+
static void call_in_pch_function(void) {
13+
in_pch_tests();
14+
}
15+
16+
void out_of_pch_tests() {
17+
A* a = new A;
18+
delete a;
19+
B *b = new B;
20+
delete b;
21+
C *c = new C;
22+
delete c;
23+
D *d = new D;
24+
delete d;
25+
E *e = new E;
26+
delete e;
27+
}

clang/test/SemaCXX/constant-expression-cxx11.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2203,6 +2203,8 @@ namespace BuiltinStrlen {
22032203
static_assert(__builtin_strlen("foo") == 3, "");
22042204
static_assert(__builtin_strlen("foo\0quux") == 3, "");
22052205
static_assert(__builtin_strlen("foo\0quux" + 4) == 4, "");
2206+
static_assert(__builtin_strlen("foo") + 1 + "foo" == "foo", ""); // expected-error {{static assertion expression is not an integral constant expression}}
2207+
// expected-note@-1 {{comparison against pointer '&"foo"[4]' that points past the end of a complete object has unspecified value}}
22062208

22072209
constexpr bool check(const char *p) {
22082210
return __builtin_strlen(p) == 3 &&

libclc/cmake/modules/AddLibclc.cmake

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -466,16 +466,22 @@ function(libclc_configure_lib_source LIB_FILE_LIST)
466466
## Add the generated convert files here to prevent adding the ones listed in
467467
## SOURCES
468468
set( rel_files ${${LIB_FILE_LIST}} ) # Source directory input files, relative to the root dir
469-
set( objects ${${LIB_FILE_LIST}} ) # A "set" of already-added input files
469+
# A "set" of already-added input files
470+
set( objects )
471+
foreach( f ${${LIB_FILE_LIST}} )
472+
get_filename_component( name ${f} NAME )
473+
list( APPEND objects ${name} )
474+
endforeach()
470475

471476
foreach( l ${source_list} )
472477
file( READ ${l} file_list )
473478
string( REPLACE "\n" ";" file_list ${file_list} )
474479
get_filename_component( dir ${l} DIRECTORY )
475480
foreach( f ${file_list} )
481+
get_filename_component( name ${f} NAME )
476482
# Only add each file once, so that targets can 'specialize' builtins
477-
if( NOT ${f} IN_LIST objects )
478-
list( APPEND objects ${f} )
483+
if( NOT ${name} IN_LIST objects )
484+
list( APPEND objects ${name} )
479485
list( APPEND rel_files ${dir}/${f} )
480486
endif()
481487
endforeach()

0 commit comments

Comments
 (0)