Skip to content

Commit ab5f87f

Browse files
committed
merge main into amd-staging
2 parents f11212c + acc6bcd commit ab5f87f

File tree

141 files changed

+3404
-1467
lines changed

Some content is hidden

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

141 files changed

+3404
-1467
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,8 @@ Modified Compiler Flags
190190

191191
- The compiler flag `-fbracket-depth` default value is increased from 256 to 2048. (#GH94728)
192192

193+
- `-Wpadded` option implemented for the `x86_64-windows-msvc` target. Fixes #61702
194+
193195
Removed Compiler Flags
194196
-------------------------
195197

clang/include/clang/Basic/Attr.td

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -936,7 +936,8 @@ def PatchableFunctionEntry
936936
"riscv64", "x86", "x86_64", "ppc", "ppc64"]>> {
937937
let Spellings = [GCC<"patchable_function_entry">];
938938
let Subjects = SubjectList<[Function, ObjCMethod]>;
939-
let Args = [UnsignedArgument<"Count">, DefaultIntArgument<"Offset", 0>];
939+
let Args = [UnsignedArgument<"Count">, DefaultIntArgument<"Offset", 0>,
940+
StringArgument<"Section", /* optional */ 1>];
940941
let Documentation = [PatchableFunctionEntryDocs];
941942
}
942943

clang/include/clang/Basic/AttrDocs.td

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6502,10 +6502,12 @@ only N==1 is supported.
65026502
def PatchableFunctionEntryDocs : Documentation {
65036503
let Category = DocCatFunction;
65046504
let Content = [{
6505-
``__attribute__((patchable_function_entry(N,M)))`` is used to generate M NOPs
6506-
before the function entry and N-M NOPs after the function entry. This attribute
6507-
takes precedence over the command line option ``-fpatchable-function-entry=N,M``.
6508-
``M`` defaults to 0 if omitted.
6505+
``__attribute__((patchable_function_entry(N,M,Section)))`` is used to generate M
6506+
NOPs before the function entry and N-M NOPs after the function entry, with a record of
6507+
the entry stored in section ``Section``. This attribute takes precedence over the
6508+
command line option ``-fpatchable-function-entry=N,M,Section``. ``M`` defaults to 0
6509+
if omitted.``Section`` defaults to the ``-fpatchable-function-entry`` section name if
6510+
set, or to ``__patchable_function_entries`` otherwise.
65096511

65106512
This attribute is only supported on
65116513
aarch64/aarch64-be/loongarch32/loongarch64/riscv32/riscv64/i386/x86-64/ppc/ppc64 targets.

clang/include/clang/Basic/CodeGenOptions.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,10 @@ class CodeGenOptions : public CodeGenOptionsBase {
296296
/// -fprofile-generate, and -fcs-profile-generate.
297297
std::string InstrProfileOutput;
298298

299+
/// Name of the patchable function entry section with
300+
/// -fpatchable-function-entry.
301+
std::string PatchableFunctionEntrySection;
302+
299303
/// Name of the profile file to use with -fprofile-sample-use.
300304
std::string SampleProfileFile;
301305

clang/include/clang/Basic/DiagnosticSemaKinds.td

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3550,6 +3550,10 @@ def err_conflicting_codeseg_attribute : Error<
35503550
def warn_duplicate_codeseg_attribute : Warning<
35513551
"duplicate code segment specifiers">, InGroup<Section>;
35523552

3553+
def err_attribute_patchable_function_entry_invalid_section
3554+
: Error<"section argument to 'patchable_function_entry' attribute is not "
3555+
"valid for this target: %0">;
3556+
35533557
def err_anonymous_property: Error<
35543558
"anonymous property is not supported">;
35553559
def err_property_is_variably_modified : Error<

clang/include/clang/Driver/Options.td

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3871,10 +3871,16 @@ defm pascal_strings : BoolFOption<"pascal-strings",
38713871
// Note: This flag has different semantics in the driver and in -cc1. The driver accepts -fpatchable-function-entry=M,N
38723872
// and forwards it to -cc1 as -fpatchable-function-entry=M and -fpatchable-function-entry-offset=N. In -cc1, both flags
38733873
// are treated as a single integer.
3874-
def fpatchable_function_entry_EQ : Joined<["-"], "fpatchable-function-entry=">, Group<f_Group>,
3875-
Visibility<[ClangOption, CC1Option]>,
3876-
MetaVarName<"<N,M>">, HelpText<"Generate M NOPs before function entry and N-M NOPs after function entry">,
3877-
MarshallingInfoInt<CodeGenOpts<"PatchableFunctionEntryCount">>;
3874+
def fpatchable_function_entry_EQ
3875+
: Joined<["-"], "fpatchable-function-entry=">,
3876+
Group<f_Group>,
3877+
Visibility<[ClangOption, CC1Option]>,
3878+
MetaVarName<"<N,M,Section>">,
3879+
HelpText<"Generate M NOPs before function entry and N-M NOPs after "
3880+
"function entry. "
3881+
"If section is specified, use it instead of "
3882+
"__patchable_function_entries.">,
3883+
MarshallingInfoInt<CodeGenOpts<"PatchableFunctionEntryCount">>;
38783884
def fms_hotpatch : Flag<["-"], "fms-hotpatch">, Group<f_Group>,
38793885
Visibility<[ClangOption, CC1Option, CLOption]>,
38803886
HelpText<"Ensure that all functions can be hotpatched at runtime">,
@@ -7753,6 +7759,11 @@ def fpatchable_function_entry_offset_EQ
77537759
: Joined<["-"], "fpatchable-function-entry-offset=">, MetaVarName<"<M>">,
77547760
HelpText<"Generate M NOPs before function entry">,
77557761
MarshallingInfoInt<CodeGenOpts<"PatchableFunctionEntryOffset">>;
7762+
def fpatchable_function_entry_section_EQ
7763+
: Joined<["-"], "fpatchable-function-entry-section=">,
7764+
MetaVarName<"<Section>">,
7765+
HelpText<"Use Section instead of __patchable_function_entries">,
7766+
MarshallingInfoString<CodeGenOpts<"PatchableFunctionEntrySection">>;
77567767
def fprofile_instrument_EQ : Joined<["-"], "fprofile-instrument=">,
77577768
HelpText<"Enable PGO instrumentation">, Values<"none,clang,llvm,csllvm">,
77587769
NormalizedValuesScope<"CodeGenOptions">,

clang/lib/AST/RecordLayoutBuilder.cpp

Lines changed: 54 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2274,9 +2274,9 @@ static unsigned getPaddingDiagFromTagKind(TagTypeKind Tag) {
22742274
}
22752275
}
22762276

2277-
void ItaniumRecordLayoutBuilder::CheckFieldPadding(
2278-
uint64_t Offset, uint64_t UnpaddedOffset, uint64_t UnpackedOffset,
2279-
unsigned UnpackedAlign, bool isPacked, const FieldDecl *D) {
2277+
static void CheckFieldPadding(const ASTContext &Context, bool IsUnion,
2278+
uint64_t Offset, uint64_t UnpaddedOffset,
2279+
const FieldDecl *D) {
22802280
// We let objc ivars without warning, objc interfaces generally are not used
22812281
// for padding tricks.
22822282
if (isa<ObjCIvarDecl>(D))
@@ -2300,23 +2300,31 @@ void ItaniumRecordLayoutBuilder::CheckFieldPadding(
23002300
if (D->getIdentifier()) {
23012301
auto Diagnostic = D->isBitField() ? diag::warn_padded_struct_bitfield
23022302
: diag::warn_padded_struct_field;
2303-
Diag(D->getLocation(), Diagnostic)
2303+
Context.getDiagnostics().Report(D->getLocation(),
2304+
Diagnostic)
23042305
<< getPaddingDiagFromTagKind(D->getParent()->getTagKind())
23052306
<< Context.getTypeDeclType(D->getParent()) << PadSize
23062307
<< (InBits ? 1 : 0) // (byte|bit)
23072308
<< D->getIdentifier();
23082309
} else {
23092310
auto Diagnostic = D->isBitField() ? diag::warn_padded_struct_anon_bitfield
23102311
: diag::warn_padded_struct_anon_field;
2311-
Diag(D->getLocation(), Diagnostic)
2312+
Context.getDiagnostics().Report(D->getLocation(),
2313+
Diagnostic)
23122314
<< getPaddingDiagFromTagKind(D->getParent()->getTagKind())
23132315
<< Context.getTypeDeclType(D->getParent()) << PadSize
23142316
<< (InBits ? 1 : 0); // (byte|bit)
23152317
}
2316-
}
2317-
if (isPacked && Offset != UnpackedOffset) {
2318-
HasPackedField = true;
2319-
}
2318+
}
2319+
}
2320+
2321+
void ItaniumRecordLayoutBuilder::CheckFieldPadding(
2322+
uint64_t Offset, uint64_t UnpaddedOffset, uint64_t UnpackedOffset,
2323+
unsigned UnpackedAlign, bool isPacked, const FieldDecl *D) {
2324+
::CheckFieldPadding(Context, IsUnion, Offset, UnpaddedOffset, D);
2325+
if (isPacked && Offset != UnpackedOffset) {
2326+
HasPackedField = true;
2327+
}
23202328
}
23212329

23222330
static const CXXMethodDecl *computeKeyFunction(ASTContext &Context,
@@ -2642,8 +2650,6 @@ struct MicrosoftRecordLayoutBuilder {
26422650
/// virtual base classes and their offsets in the record.
26432651
ASTRecordLayout::VBaseOffsetsMapTy VBases;
26442652
/// The number of remaining bits in our last bitfield allocation.
2645-
/// This value isn't meaningful unless LastFieldIsNonZeroWidthBitfield is
2646-
/// true.
26472653
unsigned RemainingBitsInField;
26482654
bool IsUnion : 1;
26492655
/// True if the last field laid out was a bitfield and was not 0
@@ -3004,6 +3010,15 @@ void MicrosoftRecordLayoutBuilder::layoutField(const FieldDecl *FD) {
30043010
} else {
30053011
FieldOffset = Size.alignTo(Info.Alignment);
30063012
}
3013+
3014+
uint64_t UnpaddedFielddOffsetInBits =
3015+
Context.toBits(DataSize) - RemainingBitsInField;
3016+
3017+
::CheckFieldPadding(Context, IsUnion, Context.toBits(FieldOffset),
3018+
UnpaddedFielddOffsetInBits, FD);
3019+
3020+
RemainingBitsInField = 0;
3021+
30073022
placeFieldAtOffset(FieldOffset);
30083023

30093024
if (!IsOverlappingEmptyField)
@@ -3049,10 +3064,14 @@ void MicrosoftRecordLayoutBuilder::layoutBitField(const FieldDecl *FD) {
30493064
} else {
30503065
// Allocate a new block of memory and place the bitfield in it.
30513066
CharUnits FieldOffset = Size.alignTo(Info.Alignment);
3067+
uint64_t UnpaddedFieldOffsetInBits =
3068+
Context.toBits(DataSize) - RemainingBitsInField;
30523069
placeFieldAtOffset(FieldOffset);
30533070
Size = FieldOffset + Info.Size;
30543071
Alignment = std::max(Alignment, Info.Alignment);
30553072
RemainingBitsInField = Context.toBits(Info.Size) - Width;
3073+
::CheckFieldPadding(Context, IsUnion, Context.toBits(FieldOffset),
3074+
UnpaddedFieldOffsetInBits, FD);
30563075
}
30573076
DataSize = Size;
30583077
}
@@ -3076,9 +3095,14 @@ MicrosoftRecordLayoutBuilder::layoutZeroWidthBitField(const FieldDecl *FD) {
30763095
} else {
30773096
// Round up the current record size to the field's alignment boundary.
30783097
CharUnits FieldOffset = Size.alignTo(Info.Alignment);
3098+
uint64_t UnpaddedFieldOffsetInBits =
3099+
Context.toBits(DataSize) - RemainingBitsInField;
30793100
placeFieldAtOffset(FieldOffset);
3101+
RemainingBitsInField = 0;
30803102
Size = FieldOffset;
30813103
Alignment = std::max(Alignment, Info.Alignment);
3104+
::CheckFieldPadding(Context, IsUnion, Context.toBits(FieldOffset),
3105+
UnpaddedFieldOffsetInBits, FD);
30823106
}
30833107
DataSize = Size;
30843108
}
@@ -3203,6 +3227,9 @@ void MicrosoftRecordLayoutBuilder::layoutVirtualBases(const CXXRecordDecl *RD) {
32033227
}
32043228

32053229
void MicrosoftRecordLayoutBuilder::finalizeLayout(const RecordDecl *RD) {
3230+
uint64_t UnpaddedSizeInBits = Context.toBits(DataSize);
3231+
UnpaddedSizeInBits -= RemainingBitsInField;
3232+
32063233
// Respect required alignment. Note that in 32-bit mode Required alignment
32073234
// may be 0 and cause size not to be updated.
32083235
DataSize = Size;
@@ -3231,6 +3258,22 @@ void MicrosoftRecordLayoutBuilder::finalizeLayout(const RecordDecl *RD) {
32313258
Size = Context.toCharUnitsFromBits(External.Size);
32323259
if (External.Align)
32333260
Alignment = Context.toCharUnitsFromBits(External.Align);
3261+
return;
3262+
}
3263+
unsigned CharBitNum = Context.getTargetInfo().getCharWidth();
3264+
uint64_t SizeInBits = Context.toBits(Size);
3265+
if (SizeInBits > UnpaddedSizeInBits) {
3266+
unsigned int PadSize = SizeInBits - UnpaddedSizeInBits;
3267+
bool InBits = true;
3268+
if (PadSize % CharBitNum == 0) {
3269+
PadSize = PadSize / CharBitNum;
3270+
InBits = false;
3271+
}
3272+
3273+
Context.getDiagnostics().Report(RD->getLocation(),
3274+
diag::warn_padded_struct_size)
3275+
<< Context.getTypeDeclType(RD) << PadSize
3276+
<< (InBits ? 1 : 0); // (byte|bit)
32343277
}
32353278
}
32363279

clang/lib/Analysis/FlowSensitive/SimplifyConstraints.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,8 @@ void simplifyConstraints(llvm::SetVector<const Formula *> &Constraints,
111111
FalseAtoms = projectToLeaders(FalseAtoms, EquivalentAtoms);
112112

113113
llvm::DenseMap<Atom, const Formula *> Substitutions;
114-
for (auto It = EquivalentAtoms.begin(); It != EquivalentAtoms.end(); ++It) {
115-
Atom TheAtom = It->getData();
114+
for (const auto &E : EquivalentAtoms) {
115+
Atom TheAtom = E->getData();
116116
Atom Leader = EquivalentAtoms.getLeaderValue(TheAtom);
117117
if (TrueAtoms.contains(Leader)) {
118118
if (FalseAtoms.contains(Leader)) {
@@ -152,9 +152,9 @@ void simplifyConstraints(llvm::SetVector<const Formula *> &Constraints,
152152

153153
if (Info) {
154154
for (const auto &E : EquivalentAtoms) {
155-
if (!E.isLeader())
155+
if (!E->isLeader())
156156
continue;
157-
Atom At = *EquivalentAtoms.findLeader(E);
157+
Atom At = *EquivalentAtoms.findLeader(*E);
158158
if (TrueAtoms.contains(At) || FalseAtoms.contains(At))
159159
continue;
160160
llvm::SmallVector<Atom> Atoms =

clang/lib/CodeGen/CGHLSLBuiltins.cpp

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -368,20 +368,12 @@ Value *CodeGenFunction::EmitHLSLBuiltinExpr(unsigned BuiltinID,
368368
"Scalar dot product is only supported on ints and floats.");
369369
}
370370
// For vectors, validate types and emit the appropriate intrinsic
371-
372-
// A VectorSplat should have happened
373-
assert(T0->isVectorTy() && T1->isVectorTy() &&
374-
"Dot product of vector and scalar is not supported.");
371+
assert(CGM.getContext().hasSameUnqualifiedType(E->getArg(0)->getType(),
372+
E->getArg(1)->getType()) &&
373+
"Dot product operands must have the same type.");
375374

376375
auto *VecTy0 = E->getArg(0)->getType()->castAs<VectorType>();
377-
[[maybe_unused]] auto *VecTy1 =
378-
E->getArg(1)->getType()->castAs<VectorType>();
379-
380-
assert(VecTy0->getElementType() == VecTy1->getElementType() &&
381-
"Dot product of vectors need the same element types.");
382-
383-
assert(VecTy0->getNumElements() == VecTy1->getNumElements() &&
384-
"Dot product requires vectors to be of the same size.");
376+
assert(VecTy0 && "Dot product argument must be a vector.");
385377

386378
return Builder.CreateIntrinsic(
387379
/*ReturnType=*/T0->getScalarType(),

clang/lib/CodeGen/CodeGenFunction.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -965,18 +965,24 @@ void CodeGenFunction::StartFunction(GlobalDecl GD, QualType RetTy,
965965
}
966966

967967
unsigned Count, Offset;
968+
StringRef Section;
968969
if (const auto *Attr =
969970
D ? D->getAttr<PatchableFunctionEntryAttr>() : nullptr) {
970971
Count = Attr->getCount();
971972
Offset = Attr->getOffset();
973+
Section = Attr->getSection();
972974
} else {
973975
Count = CGM.getCodeGenOpts().PatchableFunctionEntryCount;
974976
Offset = CGM.getCodeGenOpts().PatchableFunctionEntryOffset;
975977
}
978+
if (Section.empty())
979+
Section = CGM.getCodeGenOpts().PatchableFunctionEntrySection;
976980
if (Count && Offset <= Count) {
977981
Fn->addFnAttr("patchable-function-entry", std::to_string(Count - Offset));
978982
if (Offset)
979983
Fn->addFnAttr("patchable-function-prefix", std::to_string(Offset));
984+
if (!Section.empty())
985+
Fn->addFnAttr("patchable-function-entry-section", Section);
980986
}
981987
// Instruct that functions for COFF/CodeView targets should start with a
982988
// patchable instruction, but only on x86/x64. Don't forward this to ARM/ARM64

clang/lib/Driver/ToolChains/Clang.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7089,8 +7089,9 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
70897089
D.Diag(diag::err_drv_unsupported_opt_for_target)
70907090
<< A->getAsString(Args) << TripleStr;
70917091
else if (S.consumeInteger(10, Size) ||
7092-
(!S.empty() && (!S.consume_front(",") ||
7093-
S.consumeInteger(10, Offset) || !S.empty())))
7092+
(!S.empty() &&
7093+
(!S.consume_front(",") || S.consumeInteger(10, Offset))) ||
7094+
(!S.empty() && (!S.consume_front(",") || S.empty())))
70947095
D.Diag(diag::err_drv_invalid_argument_to_option)
70957096
<< S0 << A->getOption().getName();
70967097
else if (Size < Offset)
@@ -7099,6 +7100,9 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
70997100
CmdArgs.push_back(Args.MakeArgString(A->getSpelling() + Twine(Size)));
71007101
CmdArgs.push_back(Args.MakeArgString(
71017102
"-fpatchable-function-entry-offset=" + Twine(Offset)));
7103+
if (!S.empty())
7104+
CmdArgs.push_back(
7105+
Args.MakeArgString("-fpatchable-function-entry-section=" + S));
71027106
}
71037107
}
71047108

clang/lib/Parse/ParseOpenACC.cpp

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1274,19 +1274,32 @@ Parser::ParseOpenACCWaitArgument(SourceLocation Loc, bool IsDirective) {
12741274
ConsumeToken();
12751275
}
12761276

1277+
1278+
12771279
// OpenACC 3.3, section 2.16:
12781280
// the term 'async-argument' means a nonnegative scalar integer expression, or
12791281
// one of the special values 'acc_async_noval' or 'acc_async_sync', as defined
12801282
// in the C header file and the Fortran opacc module.
1281-
bool FirstArg = true;
1283+
OpenACCIntExprParseResult Res = ParseOpenACCAsyncArgument(
1284+
IsDirective ? OpenACCDirectiveKind::Wait
1285+
: OpenACCDirectiveKind::Invalid,
1286+
IsDirective ? OpenACCClauseKind::Invalid : OpenACCClauseKind::Wait,
1287+
Loc);
1288+
1289+
if (Res.first.isInvalid() &&
1290+
Res.second == OpenACCParseCanContinue::Cannot) {
1291+
Result.Failed = true;
1292+
return Result;
1293+
}
1294+
1295+
if (Res.first.isUsable())
1296+
Result.QueueIdExprs.push_back(Res.first.get());
1297+
12821298
while (!getCurToken().isOneOf(tok::r_paren, tok::annot_pragma_openacc_end)) {
1283-
if (!FirstArg) {
1284-
if (ExpectAndConsume(tok::comma)) {
1285-
Result.Failed = true;
1286-
return Result;
1287-
}
1299+
if (ExpectAndConsume(tok::comma)) {
1300+
Result.Failed = true;
1301+
return Result;
12881302
}
1289-
FirstArg = false;
12901303

12911304
OpenACCIntExprParseResult Res = ParseOpenACCAsyncArgument(
12921305
IsDirective ? OpenACCDirectiveKind::Wait

0 commit comments

Comments
 (0)