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

0 commit comments

Comments
 (0)