Skip to content

Commit a1b639b

Browse files
authored
merge main into amd-staging (llvm#3010)
2 parents 169815f + 379d73f commit a1b639b

File tree

136 files changed

+10252
-3358
lines changed

Some content is hidden

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

136 files changed

+10252
-3358
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -783,6 +783,11 @@ Bug Fixes in This Version
783783
flag and diagnostic because the macro injection was used to emit this warning.
784784
Unfortunately there is no other good way to diagnose usage of ``static_assert``
785785
macro without inclusion of ``<assert.h>``.
786+
- In C23, something like ``[[/*possible attributes*/]];`` is an attribute
787+
declaration, not a statement. So it is not allowed by the syntax in places
788+
where a statement is required, specifically as the secondary block of a
789+
selection or iteration statement. This differs from C++, since C++ allows
790+
declaration statements. Clang now emits a warning for these patterns. (#GH141659)
786791

787792
Bug Fixes to Compiler Builtins
788793
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

clang/include/clang/Basic/DiagnosticParseKinds.td

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,9 @@ def err_expected_while : Error<"expected 'while' in do/while loop">;
276276

277277
def err_expected_semi_after_stmt : Error<"expected ';' after %0 statement">;
278278
def err_expected_semi_after_expr : Error<"expected ';' after expression">;
279+
def warn_attr_in_secondary_block : ExtWarn<
280+
"ISO C does not allow an attribute list to appear here">,
281+
InGroup<DiagGroup<"c-attribute-extension">>;
279282
def err_extraneous_token_before_semi : Error<"extraneous '%0' before ';'">;
280283

281284
def err_expected_semi_after_method_proto : Error<

clang/include/clang/Driver/CommonArgs.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,12 @@ StringRef parseMPreferVectorWidthOption(clang::DiagnosticsEngine &Diags,
304304
StringRef parseMRecipOption(clang::DiagnosticsEngine &Diags,
305305
const llvm::opt::ArgList &Args);
306306

307+
// Convert ComplexRangeKind to a string that can be passed as a frontend option.
308+
std::string complexRangeKindToStr(LangOptions::ComplexRangeKind Range);
309+
310+
// Render a frontend option corresponding to ComplexRangeKind.
311+
std::string renderComplexRangeOption(LangOptions::ComplexRangeKind Range);
312+
307313
} // end namespace tools
308314
} // end namespace driver
309315
} // end namespace clang

clang/include/clang/Driver/Options.td

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1028,12 +1028,13 @@ defm offload_uniform_block : BoolFOption<"offload-uniform-block",
10281028
BothFlags<[], [ClangOption], " that kernels are launched with uniform block sizes (default true for CUDA/HIP and false otherwise)">>;
10291029

10301030
def fcomplex_arithmetic_EQ : Joined<["-"], "fcomplex-arithmetic=">, Group<f_Group>,
1031-
Visibility<[ClangOption, CC1Option]>,
1031+
Visibility<[ClangOption, CC1Option, FlangOption, FC1Option]>,
10321032
Values<"full,improved,promoted,basic">, NormalizedValuesScope<"LangOptions">,
1033-
NormalizedValues<["CX_Full", "CX_Improved", "CX_Promoted", "CX_Basic"]>;
1033+
NormalizedValues<["CX_Full", "CX_Improved", "CX_Promoted", "CX_Basic"]>,
1034+
HelpText<"Controls the calculation methods of complex number multiplication and division.">;
10341035

10351036
def complex_range_EQ : Joined<["-"], "complex-range=">, Group<f_Group>,
1036-
Visibility<[CC1Option]>,
1037+
Visibility<[CC1Option, FC1Option]>,
10371038
Values<"full,improved,promoted,basic">, NormalizedValuesScope<"LangOptions">,
10381039
NormalizedValues<["CX_Full", "CX_Improved", "CX_Promoted", "CX_Basic"]>,
10391040
MarshallingInfoEnum<LangOpts<"ComplexRange">, "CX_Full">;

clang/lib/CodeGen/Targets/RISCV.cpp

Lines changed: 59 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -441,98 +441,74 @@ bool RISCVABIInfo::detectVLSCCEligibleStruct(QualType Ty, unsigned ABIVLen,
441441
// __attribute__((vector_size(64))) int d;
442442
// }
443443
//
444-
// Struct of 1 fixed-length vector is passed as a scalable vector.
445-
// Struct of >1 fixed-length vectors are passed as vector tuple.
446-
// Struct of 1 array of fixed-length vectors is passed as a scalable vector.
447-
// Otherwise, pass the struct indirectly.
448-
449-
if (llvm::StructType *STy = dyn_cast<llvm::StructType>(CGT.ConvertType(Ty))) {
450-
unsigned NumElts = STy->getStructNumElements();
451-
if (NumElts > 8)
452-
return false;
444+
// 1. Struct of 1 fixed-length vector is passed as a scalable vector.
445+
// 2. Struct of >1 fixed-length vectors are passed as vector tuple.
446+
// 3. Struct of an array with 1 element of fixed-length vectors is passed as a
447+
// scalable vector.
448+
// 4. Struct of an array with >1 elements of fixed-length vectors is passed as
449+
// vector tuple.
450+
// 5. Otherwise, pass the struct indirectly.
451+
452+
llvm::StructType *STy = dyn_cast<llvm::StructType>(CGT.ConvertType(Ty));
453+
if (!STy)
454+
return false;
453455

454-
auto *FirstEltTy = STy->getElementType(0);
455-
if (!STy->containsHomogeneousTypes())
456-
return false;
456+
unsigned NumElts = STy->getStructNumElements();
457+
if (NumElts > 8)
458+
return false;
457459

458-
// Check structure of fixed-length vectors and turn them into vector tuple
459-
// type if legal.
460-
if (auto *FixedVecTy = dyn_cast<llvm::FixedVectorType>(FirstEltTy)) {
461-
if (NumElts == 1) {
462-
// Handle single fixed-length vector.
463-
VLSType = llvm::ScalableVectorType::get(
464-
FixedVecTy->getElementType(),
465-
llvm::divideCeil(FixedVecTy->getNumElements() *
466-
llvm::RISCV::RVVBitsPerBlock,
467-
ABIVLen));
468-
// Check registers needed <= 8.
469-
return llvm::divideCeil(
470-
FixedVecTy->getNumElements() *
471-
FixedVecTy->getElementType()->getScalarSizeInBits(),
472-
ABIVLen) <= 8;
473-
}
474-
// LMUL
475-
// = fixed-length vector size / ABIVLen
476-
// = 8 * I8EltCount / RVVBitsPerBlock
477-
// =>
478-
// I8EltCount
479-
// = (fixed-length vector size * RVVBitsPerBlock) / (ABIVLen * 8)
480-
unsigned I8EltCount = llvm::divideCeil(
481-
FixedVecTy->getNumElements() *
482-
FixedVecTy->getElementType()->getScalarSizeInBits() *
483-
llvm::RISCV::RVVBitsPerBlock,
484-
ABIVLen * 8);
485-
VLSType = llvm::TargetExtType::get(
486-
getVMContext(), "riscv.vector.tuple",
487-
llvm::ScalableVectorType::get(llvm::Type::getInt8Ty(getVMContext()),
488-
I8EltCount),
489-
NumElts);
490-
// Check registers needed <= 8.
491-
return NumElts *
492-
llvm::divideCeil(
493-
FixedVecTy->getNumElements() *
494-
FixedVecTy->getElementType()->getScalarSizeInBits(),
495-
ABIVLen) <=
496-
8;
497-
}
460+
auto *FirstEltTy = STy->getElementType(0);
461+
if (!STy->containsHomogeneousTypes())
462+
return false;
498463

499-
// If elements are not fixed-length vectors, it should be an array.
464+
if (auto *ArrayTy = dyn_cast<llvm::ArrayType>(FirstEltTy)) {
465+
// Only struct of single array is accepted
500466
if (NumElts != 1)
501467
return false;
468+
FirstEltTy = ArrayTy->getArrayElementType();
469+
NumElts = ArrayTy->getNumElements();
470+
}
502471

503-
// Check array of fixed-length vector and turn it into scalable vector type
504-
// if legal.
505-
if (auto *ArrTy = dyn_cast<llvm::ArrayType>(FirstEltTy)) {
506-
unsigned NumArrElt = ArrTy->getNumElements();
507-
if (NumArrElt > 8)
508-
return false;
472+
auto *FixedVecTy = dyn_cast<llvm::FixedVectorType>(FirstEltTy);
473+
if (!FixedVecTy)
474+
return false;
509475

510-
auto *ArrEltTy = dyn_cast<llvm::FixedVectorType>(ArrTy->getElementType());
511-
if (!ArrEltTy)
512-
return false;
476+
// Check registers needed <= 8.
477+
if (NumElts * llvm::divideCeil(
478+
FixedVecTy->getNumElements() *
479+
FixedVecTy->getElementType()->getScalarSizeInBits(),
480+
ABIVLen) >
481+
8)
482+
return false;
513483

514-
// LMUL
515-
// = NumArrElt * fixed-length vector size / ABIVLen
516-
// = fixed-length vector elt size * ScalVecNumElts / RVVBitsPerBlock
517-
// =>
518-
// ScalVecNumElts
519-
// = (NumArrElt * fixed-length vector size * RVVBitsPerBlock) /
520-
// (ABIVLen * fixed-length vector elt size)
521-
// = NumArrElt * num fixed-length vector elt * RVVBitsPerBlock /
522-
// ABIVLen
523-
unsigned ScalVecNumElts = llvm::divideCeil(
524-
NumArrElt * ArrEltTy->getNumElements() * llvm::RISCV::RVVBitsPerBlock,
525-
ABIVLen);
526-
VLSType = llvm::ScalableVectorType::get(ArrEltTy->getElementType(),
527-
ScalVecNumElts);
528-
// Check registers needed <= 8.
529-
return llvm::divideCeil(
530-
ScalVecNumElts *
531-
ArrEltTy->getElementType()->getScalarSizeInBits(),
532-
llvm::RISCV::RVVBitsPerBlock) <= 8;
533-
}
484+
// Turn them into scalable vector type or vector tuple type if legal.
485+
if (NumElts == 1) {
486+
// Handle single fixed-length vector.
487+
VLSType = llvm::ScalableVectorType::get(
488+
FixedVecTy->getElementType(),
489+
llvm::divideCeil(FixedVecTy->getNumElements() *
490+
llvm::RISCV::RVVBitsPerBlock,
491+
ABIVLen));
492+
return true;
534493
}
535-
return false;
494+
495+
// LMUL
496+
// = fixed-length vector size / ABIVLen
497+
// = 8 * I8EltCount / RVVBitsPerBlock
498+
// =>
499+
// I8EltCount
500+
// = (fixed-length vector size * RVVBitsPerBlock) / (ABIVLen * 8)
501+
unsigned I8EltCount =
502+
llvm::divideCeil(FixedVecTy->getNumElements() *
503+
FixedVecTy->getElementType()->getScalarSizeInBits() *
504+
llvm::RISCV::RVVBitsPerBlock,
505+
ABIVLen * 8);
506+
VLSType = llvm::TargetExtType::get(
507+
getVMContext(), "riscv.vector.tuple",
508+
llvm::ScalableVectorType::get(llvm::Type::getInt8Ty(getVMContext()),
509+
I8EltCount),
510+
NumElts);
511+
return true;
536512
}
537513

538514
// Fixed-length RVV vectors are represented as scalable vectors in function

clang/lib/Driver/ToolChains/Clang.cpp

Lines changed: 7 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -2789,29 +2789,10 @@ static void CollectArgsForIntegratedAssembler(Compilation &C,
27892789
}
27902790
}
27912791

2792-
static std::string ComplexRangeKindToStr(LangOptions::ComplexRangeKind Range) {
2793-
switch (Range) {
2794-
case LangOptions::ComplexRangeKind::CX_Full:
2795-
return "full";
2796-
break;
2797-
case LangOptions::ComplexRangeKind::CX_Basic:
2798-
return "basic";
2799-
break;
2800-
case LangOptions::ComplexRangeKind::CX_Improved:
2801-
return "improved";
2802-
break;
2803-
case LangOptions::ComplexRangeKind::CX_Promoted:
2804-
return "promoted";
2805-
break;
2806-
default:
2807-
return "";
2808-
}
2809-
}
2810-
28112792
static std::string ComplexArithmeticStr(LangOptions::ComplexRangeKind Range) {
28122793
return (Range == LangOptions::ComplexRangeKind::CX_None)
28132794
? ""
2814-
: "-fcomplex-arithmetic=" + ComplexRangeKindToStr(Range);
2795+
: "-fcomplex-arithmetic=" + complexRangeKindToStr(Range);
28152796
}
28162797

28172798
static void EmitComplexRangeDiag(const Driver &D, std::string str1,
@@ -2821,14 +2802,6 @@ static void EmitComplexRangeDiag(const Driver &D, std::string str1,
28212802
}
28222803
}
28232804

2824-
static std::string
2825-
RenderComplexRangeOption(LangOptions::ComplexRangeKind Range) {
2826-
std::string ComplexRangeStr = ComplexRangeKindToStr(Range);
2827-
if (!ComplexRangeStr.empty())
2828-
return "-complex-range=" + ComplexRangeStr;
2829-
return ComplexRangeStr;
2830-
}
2831-
28322805
static void RenderFloatingPointOptions(const ToolChain &TC, const Driver &D,
28332806
bool OFastEnabled, const ArgList &Args,
28342807
ArgStringList &CmdArgs,
@@ -2961,7 +2934,7 @@ static void RenderFloatingPointOptions(const ToolChain &TC, const Driver &D,
29612934
case options::OPT_fcx_limited_range:
29622935
if (GccRangeComplexOption.empty()) {
29632936
if (Range != LangOptions::ComplexRangeKind::CX_Basic)
2964-
EmitComplexRangeDiag(D, RenderComplexRangeOption(Range),
2937+
EmitComplexRangeDiag(D, renderComplexRangeOption(Range),
29652938
"-fcx-limited-range");
29662939
} else {
29672940
if (GccRangeComplexOption != "-fno-cx-limited-range")
@@ -2973,7 +2946,7 @@ static void RenderFloatingPointOptions(const ToolChain &TC, const Driver &D,
29732946
break;
29742947
case options::OPT_fno_cx_limited_range:
29752948
if (GccRangeComplexOption.empty()) {
2976-
EmitComplexRangeDiag(D, RenderComplexRangeOption(Range),
2949+
EmitComplexRangeDiag(D, renderComplexRangeOption(Range),
29772950
"-fno-cx-limited-range");
29782951
} else {
29792952
if (GccRangeComplexOption != "-fcx-limited-range" &&
@@ -2987,7 +2960,7 @@ static void RenderFloatingPointOptions(const ToolChain &TC, const Driver &D,
29872960
break;
29882961
case options::OPT_fcx_fortran_rules:
29892962
if (GccRangeComplexOption.empty())
2990-
EmitComplexRangeDiag(D, RenderComplexRangeOption(Range),
2963+
EmitComplexRangeDiag(D, renderComplexRangeOption(Range),
29912964
"-fcx-fortran-rules");
29922965
else
29932966
EmitComplexRangeDiag(D, GccRangeComplexOption, "-fcx-fortran-rules");
@@ -2997,7 +2970,7 @@ static void RenderFloatingPointOptions(const ToolChain &TC, const Driver &D,
29972970
break;
29982971
case options::OPT_fno_cx_fortran_rules:
29992972
if (GccRangeComplexOption.empty()) {
3000-
EmitComplexRangeDiag(D, RenderComplexRangeOption(Range),
2973+
EmitComplexRangeDiag(D, renderComplexRangeOption(Range),
30012974
"-fno-cx-fortran-rules");
30022975
} else {
30032976
if (GccRangeComplexOption != "-fno-cx-limited-range")
@@ -3470,12 +3443,12 @@ static void RenderFloatingPointOptions(const ToolChain &TC, const Driver &D,
34703443
CmdArgs.push_back("-fno-strict-float-cast-overflow");
34713444

34723445
if (Range != LangOptions::ComplexRangeKind::CX_None)
3473-
ComplexRangeStr = RenderComplexRangeOption(Range);
3446+
ComplexRangeStr = renderComplexRangeOption(Range);
34743447
if (!ComplexRangeStr.empty()) {
34753448
CmdArgs.push_back(Args.MakeArgString(ComplexRangeStr));
34763449
if (Args.hasArg(options::OPT_fcomplex_arithmetic_EQ))
34773450
CmdArgs.push_back(Args.MakeArgString("-fcomplex-arithmetic=" +
3478-
ComplexRangeKindToStr(Range)));
3451+
complexRangeKindToStr(Range)));
34793452
}
34803453
if (Args.hasArg(options::OPT_fcx_limited_range))
34813454
CmdArgs.push_back("-fcx-limited-range");

clang/lib/Driver/ToolChains/CommonArgs.cpp

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3622,3 +3622,30 @@ StringRef tools::parseMRecipOption(clang::DiagnosticsEngine &Diags,
36223622

36233623
return Out;
36243624
}
3625+
3626+
std::string tools::complexRangeKindToStr(LangOptions::ComplexRangeKind Range) {
3627+
switch (Range) {
3628+
case LangOptions::ComplexRangeKind::CX_Full:
3629+
return "full";
3630+
break;
3631+
case LangOptions::ComplexRangeKind::CX_Basic:
3632+
return "basic";
3633+
break;
3634+
case LangOptions::ComplexRangeKind::CX_Improved:
3635+
return "improved";
3636+
break;
3637+
case LangOptions::ComplexRangeKind::CX_Promoted:
3638+
return "promoted";
3639+
break;
3640+
default:
3641+
return "";
3642+
}
3643+
}
3644+
3645+
std::string
3646+
tools::renderComplexRangeOption(LangOptionsBase::ComplexRangeKind Range) {
3647+
std::string ComplexRangeStr = complexRangeKindToStr(Range);
3648+
if (!ComplexRangeStr.empty())
3649+
return "-complex-range=" + ComplexRangeStr;
3650+
return ComplexRangeStr;
3651+
}

clang/lib/Driver/ToolChains/Flang.cpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -620,6 +620,8 @@ static void addFloatingPointOptions(const Driver &D, const ArgList &Args,
620620
bool AssociativeMath = false;
621621
bool ReciprocalMath = false;
622622

623+
LangOptions::ComplexRangeKind Range = LangOptions::ComplexRangeKind::CX_None;
624+
623625
if (const Arg *A = Args.getLastArg(options::OPT_ffp_contract)) {
624626
const StringRef Val = A->getValue();
625627
if (Val == "fast" || Val == "off") {
@@ -644,6 +646,20 @@ static void addFloatingPointOptions(const Driver &D, const ArgList &Args,
644646
default:
645647
continue;
646648

649+
case options::OPT_fcomplex_arithmetic_EQ: {
650+
StringRef Val = A->getValue();
651+
if (Val == "full")
652+
Range = LangOptions::ComplexRangeKind::CX_Full;
653+
else if (Val == "improved")
654+
Range = LangOptions::ComplexRangeKind::CX_Improved;
655+
else if (Val == "basic")
656+
Range = LangOptions::ComplexRangeKind::CX_Basic;
657+
else {
658+
D.Diag(diag::err_drv_unsupported_option_argument)
659+
<< A->getSpelling() << Val;
660+
}
661+
break;
662+
}
647663
case options::OPT_fhonor_infinities:
648664
HonorINFs = true;
649665
break;
@@ -714,6 +730,13 @@ static void addFloatingPointOptions(const Driver &D, const ArgList &Args,
714730
if (!Recip.empty())
715731
CmdArgs.push_back(Args.MakeArgString("-mrecip=" + Recip));
716732

733+
if (Range != LangOptions::ComplexRangeKind::CX_None) {
734+
std::string ComplexRangeStr = renderComplexRangeOption(Range);
735+
CmdArgs.push_back(Args.MakeArgString(ComplexRangeStr));
736+
CmdArgs.push_back(Args.MakeArgString("-fcomplex-arithmetic=" +
737+
complexRangeKindToStr(Range)));
738+
}
739+
717740
if (!HonorINFs && !HonorNaNs && AssociativeMath && ReciprocalMath &&
718741
ApproxFunc && !SignedZeros &&
719742
(FPContract == "fast" || FPContract.empty())) {

0 commit comments

Comments
 (0)