Skip to content

Commit 2b15af1

Browse files
SC llvm teamSC llvm team
authored andcommitted
Merged main:213028556419 into origin/amd-gfx:0bc25009f46c
Local branch origin/amd-gfx 0bc2500 Merged main:46236f4c3dbe into origin/amd-gfx:8a9df1520f29 Remote branch main 2130285 [flang][cuda] Make sure allocator id is set for pointer allocate (llvm#129950)
2 parents 0bc2500 + 2130285 commit 2b15af1

File tree

111 files changed

+1523
-610
lines changed

Some content is hidden

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

111 files changed

+1523
-610
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,8 @@ Bug Fixes in This Version
248248
(#GH125500).
249249
- Fixed clang crash when #embed data does not fit into an array
250250
(#GH128987).
251+
- Non-local variable and non-variable declarations in the first clause of a ``for`` loop in C are no longer incorrectly
252+
considered an error in C23 mode and are allowed as an extension in earlier language modes.
251253

252254
Bug Fixes to Compiler Builtins
253255
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

clang/include/clang/Basic/Builtins.td

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4765,6 +4765,12 @@ def GetDeviceSideMangledName : LangBuiltin<"CUDA_LANG"> {
47654765
}
47664766

47674767
// HLSL
4768+
def HLSLAddUint64: LangBuiltin<"HLSL_LANG"> {
4769+
let Spellings = ["__builtin_hlsl_adduint64"];
4770+
let Attributes = [NoThrow, Const];
4771+
let Prototype = "void(...)";
4772+
}
4773+
47684774
def HLSLResourceGetPointer : LangBuiltin<"HLSL_LANG"> {
47694775
let Spellings = ["__builtin_hlsl_resource_getpointer"];
47704776
let Attributes = [NoThrow];

clang/include/clang/Basic/DiagnosticSemaKinds.td

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10709,6 +10709,11 @@ def err_vector_incorrect_num_elements : Error<
1070910709
"%select{too many|too few}0 elements in vector %select{initialization|operand}3 (expected %1 elements, have %2)">;
1071010710
def err_altivec_empty_initializer : Error<"expected initializer">;
1071110711

10712+
def err_vector_incorrect_bit_count : Error<
10713+
"incorrect number of bits in vector operand (expected %select{|a multiple of}0 %1 bits, have %2)">;
10714+
def err_integer_incorrect_bit_count : Error<
10715+
"incorrect number of bits in integer (expected %0 bits, have %1)">;
10716+
1071210717
def err_invalid_neon_type_code : Error<
1071310718
"incompatible constant for this __builtin_neon function">;
1071410719
def err_argument_invalid_range : Error<
@@ -10797,6 +10802,23 @@ def err_non_local_variable_decl_in_for : Error<
1079710802
"declaration of non-local variable in 'for' loop">;
1079810803
def err_non_variable_decl_in_for : Error<
1079910804
"non-variable declaration in 'for' loop">;
10805+
10806+
def ext_c23_non_local_variable_decl_in_for : Extension<
10807+
"declaration of non-local variable in 'for' loop is a C23 extension">,
10808+
InGroup<C23>;
10809+
10810+
def warn_c17_non_local_variable_decl_in_for : Warning<
10811+
"declaration of non-local variable in 'for' loop is incompatible with C standards before C23">,
10812+
DefaultIgnore, InGroup<CPre23Compat>;
10813+
10814+
def ext_c23_non_variable_decl_in_for : Extension<
10815+
"non-variable declaration in 'for' loop is a C23 extension">,
10816+
InGroup<C23>;
10817+
10818+
def warn_c17_non_variable_decl_in_for : Warning<
10819+
"non-variable declaration in 'for' loop is incompatible with C standards before C23">,
10820+
DefaultIgnore, InGroup<CPre23Compat>;
10821+
1080010822
def err_toomany_element_decls : Error<
1080110823
"only one element declaration is allowed">;
1080210824
def err_selector_element_not_lvalue : Error<

clang/include/clang/Basic/TargetInfo.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,7 @@ class TargetInfo : public TransferrableTargetInfo,
253253
const char *MCountName;
254254
unsigned char RegParmMax, SSERegParmMax;
255255
TargetCXXABI TheCXXABI;
256+
bool UseMicrosoftManglingForC = false;
256257
const LangASMap *AddrSpaceMap;
257258

258259
mutable StringRef PlatformName;
@@ -1344,6 +1345,11 @@ class TargetInfo : public TransferrableTargetInfo,
13441345
return TheCXXABI;
13451346
}
13461347

1348+
/// Should the Microsoft mangling scheme be used for C Calling Convention.
1349+
bool shouldUseMicrosoftCCforMangling() const {
1350+
return UseMicrosoftManglingForC;
1351+
}
1352+
13471353
/// Target the specified CPU.
13481354
///
13491355
/// \return False on error (invalid CPU name).

clang/lib/AST/Mangle.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ static CCMangling getCallingConvMangling(const ASTContext &Context,
7474
if (FD->isMain() && FD->getNumParams() == 2)
7575
return CCM_WasmMainArgcArgv;
7676

77-
if (!Triple.isOSWindows() || !Triple.isX86())
77+
if (!TI.shouldUseMicrosoftCCforMangling())
7878
return CCM_Other;
7979

8080
if (Context.getLangOpts().CPlusPlus && !isExternC(ND) &&

clang/lib/Basic/Targets/OSTargets.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -817,6 +817,7 @@ class LLVM_LIBRARY_VISIBILITY UEFITargetInfo : public OSTargetInfo<Target> {
817817
: OSTargetInfo<Target>(Triple, Opts) {
818818
this->WCharType = TargetInfo::UnsignedShort;
819819
this->WIntType = TargetInfo::UnsignedShort;
820+
this->UseMicrosoftManglingForC = true;
820821
}
821822
};
822823

@@ -837,6 +838,7 @@ class LLVM_LIBRARY_VISIBILITY WindowsTargetInfo : public OSTargetInfo<Target> {
837838
: OSTargetInfo<Target>(Triple, Opts) {
838839
this->WCharType = TargetInfo::UnsignedShort;
839840
this->WIntType = TargetInfo::UnsignedShort;
841+
this->UseMicrosoftManglingForC = true;
840842
}
841843
};
842844

clang/lib/CodeGen/CGBuiltin.cpp

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19470,6 +19470,62 @@ Value *CodeGenFunction::EmitHLSLBuiltinExpr(unsigned BuiltinID,
1947019470
return nullptr;
1947119471

1947219472
switch (BuiltinID) {
19473+
case Builtin::BI__builtin_hlsl_adduint64: {
19474+
Value *OpA = EmitScalarExpr(E->getArg(0));
19475+
Value *OpB = EmitScalarExpr(E->getArg(1));
19476+
QualType Arg0Ty = E->getArg(0)->getType();
19477+
uint64_t NumElements = Arg0Ty->castAs<VectorType>()->getNumElements();
19478+
assert(Arg0Ty == E->getArg(1)->getType() &&
19479+
"AddUint64 operand types must match");
19480+
assert(Arg0Ty->hasIntegerRepresentation() &&
19481+
"AddUint64 operands must have an integer representation");
19482+
assert((NumElements == 2 || NumElements == 4) &&
19483+
"AddUint64 operands must have 2 or 4 elements");
19484+
19485+
llvm::Value *LowA;
19486+
llvm::Value *HighA;
19487+
llvm::Value *LowB;
19488+
llvm::Value *HighB;
19489+
19490+
// Obtain low and high words of inputs A and B
19491+
if (NumElements == 2) {
19492+
LowA = Builder.CreateExtractElement(OpA, (uint64_t)0, "LowA");
19493+
HighA = Builder.CreateExtractElement(OpA, (uint64_t)1, "HighA");
19494+
LowB = Builder.CreateExtractElement(OpB, (uint64_t)0, "LowB");
19495+
HighB = Builder.CreateExtractElement(OpB, (uint64_t)1, "HighB");
19496+
} else {
19497+
LowA = Builder.CreateShuffleVector(OpA, ArrayRef<int>{0, 2}, "LowA");
19498+
HighA = Builder.CreateShuffleVector(OpA, ArrayRef<int>{1, 3}, "HighA");
19499+
LowB = Builder.CreateShuffleVector(OpB, ArrayRef<int>{0, 2}, "LowB");
19500+
HighB = Builder.CreateShuffleVector(OpB, ArrayRef<int>{1, 3}, "HighB");
19501+
}
19502+
19503+
// Use an uadd_with_overflow to compute the sum of low words and obtain a
19504+
// carry value
19505+
llvm::Value *Carry;
19506+
llvm::Value *LowSum = EmitOverflowIntrinsic(
19507+
*this, llvm::Intrinsic::uadd_with_overflow, LowA, LowB, Carry);
19508+
llvm::Value *ZExtCarry =
19509+
Builder.CreateZExt(Carry, HighA->getType(), "CarryZExt");
19510+
19511+
// Sum the high words and the carry
19512+
llvm::Value *HighSum = Builder.CreateAdd(HighA, HighB, "HighSum");
19513+
llvm::Value *HighSumPlusCarry =
19514+
Builder.CreateAdd(HighSum, ZExtCarry, "HighSumPlusCarry");
19515+
19516+
if (NumElements == 4) {
19517+
return Builder.CreateShuffleVector(LowSum, HighSumPlusCarry,
19518+
ArrayRef<int>{0, 2, 1, 3},
19519+
"hlsl.AddUint64");
19520+
}
19521+
19522+
llvm::Value *Result = PoisonValue::get(OpA->getType());
19523+
Result = Builder.CreateInsertElement(Result, LowSum, (uint64_t)0,
19524+
"hlsl.AddUint64.upto0");
19525+
Result = Builder.CreateInsertElement(Result, HighSumPlusCarry, (uint64_t)1,
19526+
"hlsl.AddUint64");
19527+
return Result;
19528+
}
1947319529
case Builtin::BI__builtin_hlsl_resource_getpointer: {
1947419530
Value *HandleOp = EmitScalarExpr(E->getArg(0));
1947519531
Value *IndexOp = EmitScalarExpr(E->getArg(1));

clang/lib/Headers/amdgpuintrin.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ __gpu_match_any_u64(uint64_t __lane_mask, uint64_t __x) {
187187
uint64_t __match_mask = 0;
188188

189189
bool __done = 0;
190-
while (__gpu_ballot(__lane_mask, __done)) {
190+
while (__gpu_ballot(__lane_mask, !__done)) {
191191
if (!__done) {
192192
uint64_t __first = __gpu_read_first_lane_u64(__lane_mask, __x);
193193
if (__first == __x) {

clang/lib/Headers/hlsl/hlsl_alias_intrinsics.h

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,27 @@ float3 acos(float3);
174174
_HLSL_BUILTIN_ALIAS(__builtin_elementwise_acos)
175175
float4 acos(float4);
176176

177+
//===----------------------------------------------------------------------===//
178+
// AddUint64 builtins
179+
//===----------------------------------------------------------------------===//
180+
181+
/// \fn T AddUint64(T a, T b)
182+
/// \brief Implements unsigned 64-bit integer addition using pairs of unsigned
183+
/// 32-bit integers.
184+
/// \param x [in] The first unsigned 32-bit integer pair(s)
185+
/// \param y [in] The second unsigned 32-bit integer pair(s)
186+
///
187+
/// This function takes one or two pairs (low, high) of unsigned 32-bit integer
188+
/// values and returns pairs (low, high) of unsigned 32-bit integer
189+
/// values representing the result of unsigned 64-bit integer addition.
190+
191+
_HLSL_AVAILABILITY(shadermodel, 6.0)
192+
_HLSL_BUILTIN_ALIAS(__builtin_hlsl_adduint64)
193+
uint32_t2 AddUint64(uint32_t2, uint32_t2);
194+
_HLSL_AVAILABILITY(shadermodel, 6.0)
195+
_HLSL_BUILTIN_ALIAS(__builtin_hlsl_adduint64)
196+
uint32_t4 AddUint64(uint32_t4, uint32_t4);
197+
177198
//===----------------------------------------------------------------------===//
178199
// all builtins
179200
//===----------------------------------------------------------------------===//

clang/lib/Headers/nvptxintrin.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ __gpu_match_any_u64(uint64_t __lane_mask, uint64_t __x) {
207207
uint64_t __match_mask = 0;
208208

209209
bool __done = 0;
210-
while (__gpu_ballot(__lane_mask, __done)) {
210+
while (__gpu_ballot(__lane_mask, !__done)) {
211211
if (!__done) {
212212
uint64_t __first = __gpu_read_first_lane_u64(__lane_mask, __x);
213213
if (__first == __x) {

0 commit comments

Comments
 (0)