Skip to content

Commit e4a6379

Browse files
committed
[AutoBump] Merge with 8f41d28 (Feb 19)
2 parents 327c8fc + 8f41d28 commit e4a6379

File tree

55 files changed

+2854
-537
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+2854
-537
lines changed

clang/lib/Basic/Targets/X86.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1109,6 +1109,10 @@ void X86TargetInfo::getTargetDefines(const LangOptions &Opts,
11091109

11101110
if (HasFloat128)
11111111
Builder.defineMacro("__SIZEOF_FLOAT128__", "16");
1112+
1113+
if (Opts.CFProtectionReturn || Opts.CFProtectionBranch)
1114+
Builder.defineMacro("__CET__", Twine{(Opts.CFProtectionReturn << 1) |
1115+
Opts.CFProtectionBranch});
11121116
}
11131117

11141118
bool X86TargetInfo::isValidFeatureName(StringRef Name) const {

clang/lib/Driver/ToolChains/MSVC.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,11 @@ void visualstudio::Linker::ConstructJob(Compilation &C, const JobAction &JA,
232232
}
233233
}
234234

235+
if (C.getDriver().isUsingLTO()) {
236+
if (Arg *A = tools::getLastProfileSampleUseArg(Args))
237+
CmdArgs.push_back(Args.MakeArgString(std::string("-lto-sample-profile:") +
238+
A->getValue()));
239+
}
235240
Args.AddAllArgValues(CmdArgs, options::OPT__SLASH_link);
236241

237242
// Control Flow Guard checks

clang/lib/Frontend/CompilerInvocation.cpp

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4776,17 +4776,6 @@ static bool ParsePreprocessorArgs(PreprocessorOptions &Opts, ArgList &Args,
47764776
}
47774777
}
47784778

4779-
// Add the __CET__ macro if a CFProtection option is set.
4780-
if (const Arg *A = Args.getLastArg(OPT_fcf_protection_EQ)) {
4781-
StringRef Name = A->getValue();
4782-
if (Name == "branch")
4783-
Opts.addMacroDef("__CET__=1");
4784-
else if (Name == "return")
4785-
Opts.addMacroDef("__CET__=2");
4786-
else if (Name == "full")
4787-
Opts.addMacroDef("__CET__=3");
4788-
}
4789-
47904779
// Add macros from the command line.
47914780
for (const auto *A : Args.filtered(OPT_D, OPT_U)) {
47924781
if (A->getOption().matches(OPT_D))

clang/lib/Sema/SemaCast.cpp

Lines changed: 54 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ namespace {
104104
void CheckStaticCast();
105105
void CheckDynamicCast();
106106
void CheckCXXCStyleCast(bool FunctionalCast, bool ListInitialization);
107+
bool CheckHLSLCStyleCast(CheckedConversionKind CCK);
107108
void CheckCStyleCast();
108109
void CheckBuiltinBitCast();
109110
void CheckAddrspaceCast();
@@ -2776,39 +2777,9 @@ void CastOperation::CheckCXXCStyleCast(bool FunctionalStyle,
27762777
CheckedConversionKind CCK = FunctionalStyle
27772778
? CheckedConversionKind::FunctionalCast
27782779
: CheckedConversionKind::CStyleCast;
2779-
2780-
QualType SrcTy = SrcExpr.get()->getType();
2781-
// This case should not trigger on regular vector cast, vector truncation
2782-
if (Self.getLangOpts().HLSL &&
2783-
Self.HLSL().CanPerformElementwiseCast(SrcExpr.get(), DestType)) {
2784-
if (SrcTy->isConstantArrayType())
2785-
SrcExpr = Self.ImpCastExprToType(
2786-
SrcExpr.get(), Self.Context.getArrayParameterType(SrcTy),
2787-
CK_HLSLArrayRValue, VK_PRValue, nullptr, CCK);
2788-
Kind = CK_HLSLElementwiseCast;
2789-
return;
2790-
}
2791-
2792-
// This case should not trigger on regular vector splat
2793-
// If the relative order of this and the HLSLElementWise cast checks
2794-
// are changed, it might change which cast handles what in a few cases
2795-
if (Self.getLangOpts().HLSL &&
2796-
Self.HLSL().CanPerformAggregateSplatCast(SrcExpr.get(), DestType)) {
2797-
const VectorType *VT = SrcTy->getAs<VectorType>();
2798-
// change splat from vec1 case to splat from scalar
2799-
if (VT && VT->getNumElements() == 1)
2800-
SrcExpr = Self.ImpCastExprToType(
2801-
SrcExpr.get(), VT->getElementType(), CK_HLSLVectorTruncation,
2802-
SrcExpr.get()->getValueKind(), nullptr, CCK);
2803-
// Inserting a scalar cast here allows for a simplified codegen in
2804-
// the case the destTy is a vector
2805-
if (const VectorType *DVT = DestType->getAs<VectorType>())
2806-
SrcExpr = Self.ImpCastExprToType(
2807-
SrcExpr.get(), DVT->getElementType(),
2808-
Self.PrepareScalarCast(SrcExpr, DVT->getElementType()),
2809-
SrcExpr.get()->getValueKind(), nullptr, CCK);
2810-
Kind = CK_HLSLAggregateSplatCast;
2811-
return;
2780+
if (Self.getLangOpts().HLSL) {
2781+
if (CheckHLSLCStyleCast(CCK))
2782+
return;
28122783
}
28132784

28142785
if (ValueKind == VK_PRValue && !DestType->isRecordType() &&
@@ -2927,6 +2898,56 @@ void CastOperation::CheckCXXCStyleCast(bool FunctionalStyle,
29272898
}
29282899
}
29292900

2901+
// CheckHLSLCStyleCast - Returns `true` ihe cast is handled or errored as an
2902+
// HLSL-specific cast. Returns false if the cast should be checked as a CXX
2903+
// C-Style cast.
2904+
bool CastOperation::CheckHLSLCStyleCast(CheckedConversionKind CCK) {
2905+
assert(Self.getLangOpts().HLSL && "Must be HLSL!");
2906+
QualType SrcTy = SrcExpr.get()->getType();
2907+
// HLSL has several unique forms of C-style casts which support aggregate to
2908+
// aggregate casting.
2909+
// This case should not trigger on regular vector cast, vector truncation
2910+
if (Self.HLSL().CanPerformElementwiseCast(SrcExpr.get(), DestType)) {
2911+
if (SrcTy->isConstantArrayType())
2912+
SrcExpr = Self.ImpCastExprToType(
2913+
SrcExpr.get(), Self.Context.getArrayParameterType(SrcTy),
2914+
CK_HLSLArrayRValue, VK_PRValue, nullptr, CCK);
2915+
Kind = CK_HLSLElementwiseCast;
2916+
return true;
2917+
}
2918+
2919+
// This case should not trigger on regular vector splat
2920+
// If the relative order of this and the HLSLElementWise cast checks
2921+
// are changed, it might change which cast handles what in a few cases
2922+
if (Self.HLSL().CanPerformAggregateSplatCast(SrcExpr.get(), DestType)) {
2923+
const VectorType *VT = SrcTy->getAs<VectorType>();
2924+
// change splat from vec1 case to splat from scalar
2925+
if (VT && VT->getNumElements() == 1)
2926+
SrcExpr = Self.ImpCastExprToType(
2927+
SrcExpr.get(), VT->getElementType(), CK_HLSLVectorTruncation,
2928+
SrcExpr.get()->getValueKind(), nullptr, CCK);
2929+
// Inserting a scalar cast here allows for a simplified codegen in
2930+
// the case the destTy is a vector
2931+
if (const VectorType *DVT = DestType->getAs<VectorType>())
2932+
SrcExpr = Self.ImpCastExprToType(
2933+
SrcExpr.get(), DVT->getElementType(),
2934+
Self.PrepareScalarCast(SrcExpr, DVT->getElementType()),
2935+
SrcExpr.get()->getValueKind(), nullptr, CCK);
2936+
Kind = CK_HLSLAggregateSplatCast;
2937+
return true;
2938+
}
2939+
2940+
// If the destination is an array, we've exhausted the valid HLSL casts, so we
2941+
// should emit a dignostic and stop processing.
2942+
if (DestType->isArrayType()) {
2943+
Self.Diag(OpRange.getBegin(), diag::err_bad_cxx_cast_generic)
2944+
<< 4 << SrcTy << DestType;
2945+
SrcExpr = ExprError();
2946+
return true;
2947+
}
2948+
return false;
2949+
}
2950+
29302951
/// DiagnoseBadFunctionCast - Warn whenever a function call is cast to a
29312952
/// non-matching type. Such as enum function call to int, int call to
29322953
/// pointer; etc. Cast to 'void' is an exception.

clang/lib/Sema/SemaInit.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6585,6 +6585,18 @@ void InitializationSequence::InitializeFrom(Sema &S,
65856585
}
65866586
}
65876587

6588+
if (S.getLangOpts().HLSL && Initializer && isa<ConstantArrayType>(DestAT)) {
6589+
QualType SrcType = Entity.getType();
6590+
if (SrcType->isArrayParameterType())
6591+
SrcType =
6592+
cast<ArrayParameterType>(SrcType)->getConstantArrayType(Context);
6593+
if (S.Context.hasSameUnqualifiedType(DestType, SrcType)) {
6594+
TryArrayCopy(S, Kind, Entity, Initializer, DestType, *this,
6595+
TreatUnavailableAsInvalid);
6596+
return;
6597+
}
6598+
}
6599+
65886600
// Some kinds of initialization permit an array to be initialized from
65896601
// another array of the same type, and perform elementwise initialization.
65906602
if (Initializer && isa<ConstantArrayType>(DestAT) &&

clang/test/Driver/cl-link.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,3 +71,6 @@
7171
// RUN: %clang_cl -m32 -arch:IA32 --target=i386-pc-win32 /Tc%s -fuse-ld=lld -### -fsanitize=address 2>&1 | FileCheck --check-prefix=INFER-LLD %s
7272
// INFER-LLD: lld-link
7373
// INFER-LLD-NOT: INFERASANLIBS
74+
75+
// RUN: %clang_cl --target=x86_64-unknown-windows-msvc /Tc%s -flto -fuse-ld=lld -### -fprofile-sample-use=%S/Inputs/file.prof 2>&1 | FileCheck -check-prefix=CHECK-SAMPLE-PROFILE %s
76+
// CHECK-SAMPLE-PROFILE: "-lto-sample-profile:{{.*}}/file.prof"

clang/test/Preprocessor/riscv-cf-protection-return.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,5 +40,7 @@
4040
// RUN: -menable-experimental-extensions -fcf-protection=full -E -dM %s -o - \
4141
// RUN: | FileCheck --check-prefixes=SHSTK-MACRO %s
4242

43+
// SHSTK-MACRO-NOT: __CET__
4344
// SHSTK-MACRO: __riscv_shadow_stack 1{{$}}
45+
// SHSTK-MACRO-NOT: __CET__
4446
// NO-MACRO-NOT: __riscv_shadow_stack
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.3-library %s -ast-dump | FileCheck %s
2+
3+
typedef vector<int,4> int8[2];
4+
5+
export void fn(int8 A) {
6+
int8 a = {A};
7+
// CHECK-LABEL: VarDecl {{.*}} b 'int8':'vector<int, 4>[2]' cinit
8+
// CHECK-NEXT: ArrayInitLoopExpr {{.*}} 'int8':'vector<int, 4>[2]'
9+
// CHECK-NEXT: OpaqueValueExpr {{.*}} 'int8':'vector<int, 4>[2]' lvalue
10+
// CHECK-NEXT: DeclRefExpr {{.*}} 'int8':'vector<int, 4>[2]' lvalue Var {{.*}} 'a' 'int8':'vector<int, 4>[2]'
11+
// CHECK-NEXT: ImplicitCastExpr {{.*}} 'vector<int, 4>' <LValueToRValue>
12+
// CHECK-NEXT: ArraySubscriptExpr {{.*}} 'vector<int, 4>' lvalue
13+
// CHECK-NEXT: ImplicitCastExpr {{.*}} 'vector<int, 4> *' <ArrayToPointerDecay>
14+
// CHECK-NEXT: OpaqueValueExpr {{.*}} 'int8':'vector<int, 4>[2]' lvalue
15+
// CHECK-NEXT: DeclRefExpr {{.*}} 'int8':'vector<int, 4>[2]' lvalue Var {{.*}} 'a' 'int8':'vector<int, 4>[2]'
16+
// CHECK-NEXT: ArrayInitIndexExpr {{.*}} 'unsigned long'
17+
int8 b = a;
18+
19+
// CHECK-LABEL: VarDecl {{.*}} c 'int8':'vector<int, 4>[2]' cinit
20+
// CHECK-NEXT: ArrayInitLoopExpr {{.*}} 'int8':'vector<int, 4>[2]'
21+
// CHECK-NEXT: OpaqueValueExpr {{.*}} 'vector<int, 4>[2]' lvalue
22+
// CHECK-NEXT: DeclRefExpr {{.*}} 'vector<int, 4>[2]' lvalue ParmVar {{.*}} 'A' 'vector<int, 4>[2]'
23+
// CHECK-NEXT: ImplicitCastExpr {{.*}} 'vector<int, 4>' <LValueToRValue>
24+
// CHECK-NEXT: ArraySubscriptExpr {{.*}} 'vector<int, 4>' lvalue
25+
// CHECK-NEXT: ImplicitCastExpr {{.*}} 'vector<int, 4> *' <ArrayToPointerDecay>
26+
// CHECK-NEXT: OpaqueValueExpr {{.*}} 'vector<int, 4>[2]' lvalue
27+
// CHECK-NEXT: DeclRefExpr {{.*}} 'vector<int, 4>[2]' lvalue ParmVar {{.*}} 'A' 'vector<int, 4>[2]'
28+
// CHECK-NEXT: ArrayInitIndexExpr {{.*}} 'unsigned long'
29+
int8 c = A;
30+
}
31+
32+
33+
34+

clang/test/SemaHLSL/Language/ElementwiseCast-errors.hlsl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ export void cantCast() {
44
int A[3] = {1,2,3};
55
int B[4] = {1,2,3,4};
66
B = (int[4])A;
7-
// expected-error@-1 {{C-style cast from 'int *' to 'int[4]' is not allowed}}
7+
// expected-error@-1 {{C-style cast from 'int[3]' to 'int[4]' is not allowed}}
88
}
99

1010
struct S {

clang/tools/c-index-test/c-index-test.c

Lines changed: 36 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1213,28 +1213,36 @@ static void PrintCursor(CXCursor Cursor, const char *CommentSchemaFile) {
12131213
}
12141214
}
12151215

1216-
static const char* GetCursorSource(CXCursor Cursor) {
1216+
static CXString createCXString(const char *CS) {
1217+
CXString Str;
1218+
Str.data = (const void *)CS;
1219+
Str.private_flags = 0;
1220+
return Str;
1221+
}
1222+
1223+
static CXString duplicateCXString(const char *CS) {
1224+
CXString Str;
1225+
Str.data = strdup(CS);
1226+
Str.private_flags = 1; // CXS_Malloc
1227+
return Str;
1228+
}
1229+
1230+
static CXString GetCursorSource(CXCursor Cursor) {
12171231
CXSourceLocation Loc = clang_getCursorLocation(Cursor);
12181232
CXString source;
12191233
CXFile file;
1234+
const char *b;
1235+
CXString result;
12201236
clang_getExpansionLocation(Loc, &file, 0, 0, 0);
12211237
source = clang_getFileName(file);
12221238
if (!clang_getCString(source)) {
12231239
clang_disposeString(source);
1224-
return "<invalid loc>";
1225-
}
1226-
else {
1227-
const char *b = basename(clang_getCString(source));
1228-
clang_disposeString(source);
1229-
return b;
1240+
return createCXString("<invalid loc>");
12301241
}
1231-
}
1232-
1233-
static CXString createCXString(const char *CS) {
1234-
CXString Str;
1235-
Str.data = (const void *) CS;
1236-
Str.private_flags = 0;
1237-
return Str;
1242+
b = basename(clang_getCString(source));
1243+
result = duplicateCXString(b);
1244+
clang_disposeString(source);
1245+
return result;
12381246
}
12391247

12401248
/******************************************************************************/
@@ -1357,9 +1365,12 @@ enum CXChildVisitResult FilteredPrintingVisitor(CXCursor Cursor,
13571365
if (!Data->Filter || (Cursor.kind == *(enum CXCursorKind *)Data->Filter)) {
13581366
CXSourceLocation Loc = clang_getCursorLocation(Cursor);
13591367
unsigned line, column;
1368+
CXString source;
13601369
clang_getFileLocation(Loc, 0, &line, &column, 0);
1361-
printf("// %s: %s:%d:%d: ", FileCheckPrefix,
1362-
GetCursorSource(Cursor), line, column);
1370+
source = GetCursorSource(Cursor);
1371+
printf("// %s: %s:%d:%d: ", FileCheckPrefix, clang_getCString(source), line,
1372+
column);
1373+
clang_disposeString(source);
13631374
PrintCursor(Cursor, Data->CommentSchemaFile);
13641375
PrintCursorExtent(Cursor);
13651376
if (clang_isDeclaration(Cursor.kind)) {
@@ -1428,8 +1439,10 @@ static enum CXChildVisitResult FunctionScanVisitor(CXCursor Cursor,
14281439
if (Ref.kind == CXCursor_NoDeclFound) {
14291440
/* Nothing found here; that's fine. */
14301441
} else if (Ref.kind != CXCursor_FunctionDecl) {
1431-
printf("// %s: %s:%d:%d: ", FileCheckPrefix, GetCursorSource(Ref),
1432-
curLine, curColumn);
1442+
CXString CursorSource = GetCursorSource(Ref);
1443+
printf("// %s: %s:%d:%d: ", FileCheckPrefix,
1444+
clang_getCString(CursorSource), curLine, curColumn);
1445+
clang_disposeString(CursorSource);
14331446
PrintCursor(Ref, Data->CommentSchemaFile);
14341447
printf("\n");
14351448
}
@@ -1451,11 +1464,15 @@ enum CXChildVisitResult USRVisitor(CXCursor C, CXCursor parent,
14511464
if (!Data->Filter || (C.kind == *(enum CXCursorKind *)Data->Filter)) {
14521465
CXString USR = clang_getCursorUSR(C);
14531466
const char *cstr = clang_getCString(USR);
1467+
CXString CursorSource;
14541468
if (!cstr || cstr[0] == '\0') {
14551469
clang_disposeString(USR);
14561470
return CXChildVisit_Recurse;
14571471
}
1458-
printf("// %s: %s %s", FileCheckPrefix, GetCursorSource(C), cstr);
1472+
CursorSource = GetCursorSource(C);
1473+
printf("// %s: %s %s", FileCheckPrefix, clang_getCString(CursorSource),
1474+
cstr);
1475+
clang_disposeString(CursorSource);
14591476

14601477
PrintCursorExtent(C);
14611478
printf("\n");

0 commit comments

Comments
 (0)