Skip to content

Commit 31193bc

Browse files
committed
Merge from 'main' to 'sycl-web' (26 commits)
CONFLICT (content): Merge conflict in clang/lib/Driver/ToolChains/Clang.cpp
2 parents 365faf3 + c990001 commit 31193bc

File tree

137 files changed

+9588
-3319
lines changed

Some content is hidden

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

137 files changed

+9588
-3319
lines changed

clang/docs/ReleaseNotes.rst

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

771776
Bug Fixes to Compiler Builtins
772777
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

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
@@ -290,6 +290,12 @@ StringRef parseMPreferVectorWidthOption(clang::DiagnosticsEngine &Diags,
290290
StringRef parseMRecipOption(clang::DiagnosticsEngine &Diags,
291291
const llvm::opt::ArgList &Args);
292292

293+
// Convert ComplexRangeKind to a string that can be passed as a frontend option.
294+
std::string complexRangeKindToStr(LangOptions::ComplexRangeKind Range);
295+
296+
// Render a frontend option corresponding to ComplexRangeKind.
297+
std::string renderComplexRangeOption(LangOptions::ComplexRangeKind Range);
298+
293299
} // end namespace tools
294300
} // end namespace driver
295301
} // end namespace clang

clang/include/clang/Driver/Options.td

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

10821082
def fcomplex_arithmetic_EQ : Joined<["-"], "fcomplex-arithmetic=">, Group<f_Group>,
1083-
Visibility<[ClangOption, CC1Option]>,
1083+
Visibility<[ClangOption, CC1Option, FlangOption, FC1Option]>,
10841084
Values<"full,improved,promoted,basic">, NormalizedValuesScope<"LangOptions">,
1085-
NormalizedValues<["CX_Full", "CX_Improved", "CX_Promoted", "CX_Basic"]>;
1085+
NormalizedValues<["CX_Full", "CX_Improved", "CX_Promoted", "CX_Basic"]>,
1086+
HelpText<"Controls the calculation methods of complex number multiplication and division.">;
10861087

10871088
def complex_range_EQ : Joined<["-"], "complex-range=">, Group<f_Group>,
1088-
Visibility<[CC1Option]>,
1089+
Visibility<[CC1Option, FC1Option]>,
10891090
Values<"full,improved,promoted,basic">, NormalizedValuesScope<"LangOptions">,
10901091
NormalizedValues<["CX_Full", "CX_Improved", "CX_Promoted", "CX_Basic"]>,
10911092
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
@@ -2828,29 +2828,10 @@ static void CollectArgsForIntegratedAssembler(Compilation &C,
28282828
}
28292829
}
28302830

2831-
static std::string ComplexRangeKindToStr(LangOptions::ComplexRangeKind Range) {
2832-
switch (Range) {
2833-
case LangOptions::ComplexRangeKind::CX_Full:
2834-
return "full";
2835-
break;
2836-
case LangOptions::ComplexRangeKind::CX_Basic:
2837-
return "basic";
2838-
break;
2839-
case LangOptions::ComplexRangeKind::CX_Improved:
2840-
return "improved";
2841-
break;
2842-
case LangOptions::ComplexRangeKind::CX_Promoted:
2843-
return "promoted";
2844-
break;
2845-
default:
2846-
return "";
2847-
}
2848-
}
2849-
28502831
static std::string ComplexArithmeticStr(LangOptions::ComplexRangeKind Range) {
28512832
return (Range == LangOptions::ComplexRangeKind::CX_None)
28522833
? ""
2853-
: "-fcomplex-arithmetic=" + ComplexRangeKindToStr(Range);
2834+
: "-fcomplex-arithmetic=" + complexRangeKindToStr(Range);
28542835
}
28552836

28562837
static void EmitComplexRangeDiag(const Driver &D, std::string str1,
@@ -2860,14 +2841,6 @@ static void EmitComplexRangeDiag(const Driver &D, std::string str1,
28602841
}
28612842
}
28622843

2863-
static std::string
2864-
RenderComplexRangeOption(LangOptions::ComplexRangeKind Range) {
2865-
std::string ComplexRangeStr = ComplexRangeKindToStr(Range);
2866-
if (!ComplexRangeStr.empty())
2867-
return "-complex-range=" + ComplexRangeStr;
2868-
return ComplexRangeStr;
2869-
}
2870-
28712844
static void EmitAccuracyDiag(const Driver &D, const JobAction &JA,
28722845
StringRef AccuracValStr, StringRef TargetPrecStr) {
28732846
if (JA.isDeviceOffloading(Action::OFK_SYCL)) {
@@ -3066,7 +3039,7 @@ static void RenderFloatingPointOptions(const ToolChain &TC, const Driver &D,
30663039
case options::OPT_fcx_limited_range:
30673040
if (GccRangeComplexOption.empty()) {
30683041
if (Range != LangOptions::ComplexRangeKind::CX_Basic)
3069-
EmitComplexRangeDiag(D, RenderComplexRangeOption(Range),
3042+
EmitComplexRangeDiag(D, renderComplexRangeOption(Range),
30703043
"-fcx-limited-range");
30713044
} else {
30723045
if (GccRangeComplexOption != "-fno-cx-limited-range")
@@ -3078,7 +3051,7 @@ static void RenderFloatingPointOptions(const ToolChain &TC, const Driver &D,
30783051
break;
30793052
case options::OPT_fno_cx_limited_range:
30803053
if (GccRangeComplexOption.empty()) {
3081-
EmitComplexRangeDiag(D, RenderComplexRangeOption(Range),
3054+
EmitComplexRangeDiag(D, renderComplexRangeOption(Range),
30823055
"-fno-cx-limited-range");
30833056
} else {
30843057
if (GccRangeComplexOption != "-fcx-limited-range" &&
@@ -3092,7 +3065,7 @@ static void RenderFloatingPointOptions(const ToolChain &TC, const Driver &D,
30923065
break;
30933066
case options::OPT_fcx_fortran_rules:
30943067
if (GccRangeComplexOption.empty())
3095-
EmitComplexRangeDiag(D, RenderComplexRangeOption(Range),
3068+
EmitComplexRangeDiag(D, renderComplexRangeOption(Range),
30963069
"-fcx-fortran-rules");
30973070
else
30983071
EmitComplexRangeDiag(D, GccRangeComplexOption, "-fcx-fortran-rules");
@@ -3102,7 +3075,7 @@ static void RenderFloatingPointOptions(const ToolChain &TC, const Driver &D,
31023075
break;
31033076
case options::OPT_fno_cx_fortran_rules:
31043077
if (GccRangeComplexOption.empty()) {
3105-
EmitComplexRangeDiag(D, RenderComplexRangeOption(Range),
3078+
EmitComplexRangeDiag(D, renderComplexRangeOption(Range),
31063079
"-fno-cx-fortran-rules");
31073080
} else {
31083081
if (GccRangeComplexOption != "-fno-cx-limited-range")
@@ -3591,12 +3564,12 @@ static void RenderFloatingPointOptions(const ToolChain &TC, const Driver &D,
35913564
CmdArgs.push_back("-fno-strict-float-cast-overflow");
35923565

35933566
if (Range != LangOptions::ComplexRangeKind::CX_None)
3594-
ComplexRangeStr = RenderComplexRangeOption(Range);
3567+
ComplexRangeStr = renderComplexRangeOption(Range);
35953568
if (!ComplexRangeStr.empty()) {
35963569
CmdArgs.push_back(Args.MakeArgString(ComplexRangeStr));
35973570
if (Args.hasArg(options::OPT_fcomplex_arithmetic_EQ))
35983571
CmdArgs.push_back(Args.MakeArgString("-fcomplex-arithmetic=" +
3599-
ComplexRangeKindToStr(Range)));
3572+
complexRangeKindToStr(Range)));
36003573
}
36013574
if (Args.hasArg(options::OPT_fcx_limited_range))
36023575
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
@@ -3447,3 +3447,30 @@ StringRef tools::parseMRecipOption(clang::DiagnosticsEngine &Diags,
34473447

34483448
return Out;
34493449
}
3450+
3451+
std::string tools::complexRangeKindToStr(LangOptions::ComplexRangeKind Range) {
3452+
switch (Range) {
3453+
case LangOptions::ComplexRangeKind::CX_Full:
3454+
return "full";
3455+
break;
3456+
case LangOptions::ComplexRangeKind::CX_Basic:
3457+
return "basic";
3458+
break;
3459+
case LangOptions::ComplexRangeKind::CX_Improved:
3460+
return "improved";
3461+
break;
3462+
case LangOptions::ComplexRangeKind::CX_Promoted:
3463+
return "promoted";
3464+
break;
3465+
default:
3466+
return "";
3467+
}
3468+
}
3469+
3470+
std::string
3471+
tools::renderComplexRangeOption(LangOptionsBase::ComplexRangeKind Range) {
3472+
std::string ComplexRangeStr = complexRangeKindToStr(Range);
3473+
if (!ComplexRangeStr.empty())
3474+
return "-complex-range=" + ComplexRangeStr;
3475+
return ComplexRangeStr;
3476+
}

clang/lib/Driver/ToolChains/Flang.cpp

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

615+
LangOptions::ComplexRangeKind Range = LangOptions::ComplexRangeKind::CX_None;
616+
615617
if (const Arg *A = Args.getLastArg(options::OPT_ffp_contract)) {
616618
const StringRef Val = A->getValue();
617619
if (Val == "fast" || Val == "off") {
@@ -636,6 +638,20 @@ static void addFloatingPointOptions(const Driver &D, const ArgList &Args,
636638
default:
637639
continue;
638640

641+
case options::OPT_fcomplex_arithmetic_EQ: {
642+
StringRef Val = A->getValue();
643+
if (Val == "full")
644+
Range = LangOptions::ComplexRangeKind::CX_Full;
645+
else if (Val == "improved")
646+
Range = LangOptions::ComplexRangeKind::CX_Improved;
647+
else if (Val == "basic")
648+
Range = LangOptions::ComplexRangeKind::CX_Basic;
649+
else {
650+
D.Diag(diag::err_drv_unsupported_option_argument)
651+
<< A->getSpelling() << Val;
652+
}
653+
break;
654+
}
639655
case options::OPT_fhonor_infinities:
640656
HonorINFs = true;
641657
break;
@@ -706,6 +722,13 @@ static void addFloatingPointOptions(const Driver &D, const ArgList &Args,
706722
if (!Recip.empty())
707723
CmdArgs.push_back(Args.MakeArgString("-mrecip=" + Recip));
708724

725+
if (Range != LangOptions::ComplexRangeKind::CX_None) {
726+
std::string ComplexRangeStr = renderComplexRangeOption(Range);
727+
CmdArgs.push_back(Args.MakeArgString(ComplexRangeStr));
728+
CmdArgs.push_back(Args.MakeArgString("-fcomplex-arithmetic=" +
729+
complexRangeKindToStr(Range)));
730+
}
731+
709732
if (!HonorINFs && !HonorNaNs && AssociativeMath && ReciprocalMath &&
710733
ApproxFunc && !SignedZeros &&
711734
(FPContract == "fast" || FPContract.empty())) {

0 commit comments

Comments
 (0)