Skip to content

Commit 7f46a4c

Browse files
committed
merge main into amd-staging
3 xfails flang: atomics flang/test/Lower/OpenMP/atomic-implicit-cast.f90 flang/test/Lower/OpenMP/common-atomic-lowering.f90 flang/test/Semantics/OpenMP/atomic.f90
2 parents a4ba17e + 52583b3 commit 7f46a4c

File tree

388 files changed

+11629
-8888
lines changed

Some content is hidden

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

388 files changed

+11629
-8888
lines changed

.github/workflows/libcxx-build-and-test.yaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@ jobs:
5252
cxx: [ 'clang++-21' ]
5353
include:
5454
- config: 'generic-gcc'
55-
cc: 'gcc-14'
56-
cxx: 'g++-14'
55+
cc: 'gcc-15'
56+
cxx: 'g++-15'
5757
steps:
5858
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
5959
- name: ${{ matrix.config }}.${{ matrix.cxx }}
@@ -92,8 +92,8 @@ jobs:
9292
cxx: [ 'clang++-21' ]
9393
include:
9494
- config: 'generic-gcc-cxx11'
95-
cc: 'gcc-14'
96-
cxx: 'g++-14'
95+
cc: 'gcc-15'
96+
cxx: 'g++-15'
9797
- config: 'generic-cxx26'
9898
cc: 'clang-20'
9999
cxx: 'clang++-20'

clang/docs/ReleaseNotes.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1122,6 +1122,9 @@ OpenMP Support
11221122
- An error is now emitted when OpenMP ``collapse`` and ``ordered`` clauses have
11231123
an argument larger than what can fit within a 64-bit integer.
11241124
- Added support for private variable reduction.
1125+
- Fixed mapping of arrays of structs containing nested structs with user defined
1126+
mappers, by using compiler-generated default mappers for the outer structs for
1127+
such maps.
11251128

11261129
Improvements
11271130
^^^^^^^^^^^^

clang/include/clang/CIR/Dialect/IR/CIROps.td

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2277,6 +2277,38 @@ def VecTernaryOp : CIR_Op<"vec.ternary",
22772277
let hasFolder = 1;
22782278
}
22792279

2280+
//===----------------------------------------------------------------------===//
2281+
// VecSplatOp
2282+
//===----------------------------------------------------------------------===//
2283+
2284+
def VecSplatOp : CIR_Op<"vec.splat", [Pure,
2285+
TypesMatchWith<"type of 'value' matches element type of 'result'", "result",
2286+
"value", "cast<VectorType>($_self).getElementType()">]> {
2287+
2288+
let summary = "Convert a scalar into a vector";
2289+
let description = [{
2290+
The `cir.vec.splat` operation creates a vector value from a scalar value.
2291+
All elements of the vector have the same value, that of the given scalar.
2292+
2293+
It's a separate operation from `cir.vec.create` because more
2294+
efficient LLVM IR can be generated for it, and because some optimization and
2295+
analysis passes can benefit from knowing that all elements of the vector
2296+
have the same value.
2297+
2298+
```mlir
2299+
%value = cir.const #cir.int<3> : !s32i
2300+
%value_vec = cir.vec.splat %value : !s32i, !cir.vector<4 x !s32i>
2301+
```
2302+
}];
2303+
2304+
let arguments = (ins CIR_VectorElementType:$value);
2305+
let results = (outs CIR_VectorType:$result);
2306+
2307+
let assemblyFormat = [{
2308+
$value `:` type($value) `,` qualified(type($result)) attr-dict
2309+
}];
2310+
}
2311+
22802312
//===----------------------------------------------------------------------===//
22812313
// BaseClassAddrOp
22822314
//===----------------------------------------------------------------------===//

clang/include/clang/CIR/MissingFeatures.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,6 @@ struct MissingFeatures {
8383
static bool opFuncSetComdat() { return false; }
8484

8585
// CallOp handling
86-
static bool opCallBuiltinFunc() { return false; }
8786
static bool opCallPseudoDtor() { return false; }
8887
static bool opCallAggregateArgs() { return false; }
8988
static bool opCallPaddingArgs() { return false; }
@@ -225,6 +224,8 @@ struct MissingFeatures {
225224
static bool isMemcpyEquivalentSpecialMember() { return false; }
226225
static bool isTrivialCtorOrDtor() { return false; }
227226
static bool implicitConstructorArgs() { return false; }
227+
static bool intrinsics() { return false; }
228+
static bool attributeNoBuiltin() { return false; }
228229

229230
// Missing types
230231
static bool dataMemberType() { return false; }

clang/include/clang/StaticAnalyzer/Core/PathSensitive/SMTConv.h

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
#include "clang/StaticAnalyzer/Core/PathSensitive/SymbolManager.h"
1919
#include "llvm/Support/SMTAPI.h"
2020

21+
#include <algorithm>
22+
2123
namespace clang {
2224
namespace ento {
2325

@@ -570,23 +572,35 @@ class SMTConv {
570572
// TODO: Refactor to put elsewhere
571573
static inline QualType getAPSIntType(ASTContext &Ctx,
572574
const llvm::APSInt &Int) {
573-
return Ctx.getIntTypeForBitwidth(Int.getBitWidth(), Int.isSigned());
575+
const QualType Ty =
576+
Ctx.getIntTypeForBitwidth(Int.getBitWidth(), Int.isSigned());
577+
if (!Ty.isNull())
578+
return Ty;
579+
// If Ty is Null, could be because the original type was a _BitInt.
580+
// Get the size of the _BitInt type (expressed in bits) and round it up to
581+
// the next power of 2 that is at least the bit size of 'char' (usually 8).
582+
unsigned CharTypeSize = Ctx.getTypeSize(Ctx.CharTy);
583+
unsigned Pow2DestWidth =
584+
std::max(llvm::bit_ceil(Int.getBitWidth()), CharTypeSize);
585+
return Ctx.getIntTypeForBitwidth(Pow2DestWidth, Int.isSigned());
574586
}
575587

576588
// Get the QualTy for the input APSInt, and fix it if it has a bitwidth of 1.
577589
static inline std::pair<llvm::APSInt, QualType>
578590
fixAPSInt(ASTContext &Ctx, const llvm::APSInt &Int) {
579591
llvm::APSInt NewInt;
592+
unsigned APSIntBitwidth = Int.getBitWidth();
593+
QualType Ty = getAPSIntType(Ctx, Int);
580594

581595
// FIXME: This should be a cast from a 1-bit integer type to a boolean type,
582596
// but the former is not available in Clang. Instead, extend the APSInt
583597
// directly.
584-
if (Int.getBitWidth() == 1 && getAPSIntType(Ctx, Int).isNull()) {
585-
NewInt = Int.extend(Ctx.getTypeSize(Ctx.BoolTy));
586-
} else
587-
NewInt = Int;
588-
589-
return std::make_pair(NewInt, getAPSIntType(Ctx, NewInt));
598+
if (APSIntBitwidth == 1 && Ty.isNull())
599+
return {Int.extend(Ctx.getTypeSize(Ctx.BoolTy)),
600+
getAPSIntType(Ctx, NewInt)};
601+
if (llvm::isPowerOf2_32(APSIntBitwidth) || Ty.isNull())
602+
return {Int, Ty};
603+
return {Int.extend(Ctx.getTypeSize(Ty)), Ty};
590604
}
591605

592606
// Perform implicit type conversion on binary symbolic expressions.

clang/lib/AST/ByteCode/InterpBuiltin.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1321,7 +1321,7 @@ static bool interp__builtin_ia32_pdep(InterpState &S, CodePtr OpPC,
13211321
if (Mask[I])
13221322
Result.setBitVal(I, Val[P++]);
13231323
}
1324-
pushInteger(S, Result, Call->getType());
1324+
pushInteger(S, std::move(Result), Call->getType());
13251325
return true;
13261326
}
13271327

@@ -1344,7 +1344,7 @@ static bool interp__builtin_ia32_pext(InterpState &S, CodePtr OpPC,
13441344
if (Mask[I])
13451345
Result.setBitVal(P++, Val[I]);
13461346
}
1347-
pushInteger(S, Result, Call->getType());
1347+
pushInteger(S, std::move(Result), Call->getType());
13481348
return true;
13491349
}
13501350

clang/lib/CIR/CodeGen/CIRGenBuilder.cpp

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,34 @@ mlir::Value CIRGenBuilderTy::getArrayElement(mlir::Location arrayLocBegin,
3939
return create<cir::PtrStrideOp>(arrayLocEnd, flatPtrTy, basePtr, idx);
4040
}
4141

42+
cir::ConstantOp CIRGenBuilderTy::getConstInt(mlir::Location loc,
43+
llvm::APSInt intVal) {
44+
bool isSigned = intVal.isSigned();
45+
unsigned width = intVal.getBitWidth();
46+
cir::IntType t = isSigned ? getSIntNTy(width) : getUIntNTy(width);
47+
return getConstInt(loc, t,
48+
isSigned ? intVal.getSExtValue() : intVal.getZExtValue());
49+
}
50+
51+
cir::ConstantOp CIRGenBuilderTy::getConstInt(mlir::Location loc,
52+
llvm::APInt intVal) {
53+
return getConstInt(loc, llvm::APSInt(intVal));
54+
}
55+
56+
cir::ConstantOp CIRGenBuilderTy::getConstInt(mlir::Location loc, mlir::Type t,
57+
uint64_t c) {
58+
assert(mlir::isa<cir::IntType>(t) && "expected cir::IntType");
59+
return create<cir::ConstantOp>(loc, cir::IntAttr::get(t, c));
60+
}
61+
62+
cir::ConstantOp
63+
clang::CIRGen::CIRGenBuilderTy::getConstFP(mlir::Location loc, mlir::Type t,
64+
llvm::APFloat fpVal) {
65+
assert(mlir::isa<cir::CIRFPTypeInterface>(t) &&
66+
"expected floating point type");
67+
return create<cir::ConstantOp>(loc, getAttr<cir::FPAttr>(t, fpVal));
68+
}
69+
4270
// This can't be defined in Address.h because that file is included by
4371
// CIRGenBuilder.h
4472
Address Address::withElementType(CIRGenBuilderTy &builder,

clang/lib/CIR/CodeGen/CIRGenBuilder.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,12 @@
1111

1212
#include "Address.h"
1313
#include "CIRGenTypeCache.h"
14+
#include "clang/CIR/Interfaces/CIRFPTypeInterface.h"
1415
#include "clang/CIR/MissingFeatures.h"
1516

1617
#include "clang/CIR/Dialect/Builder/CIRBaseBuilder.h"
1718
#include "clang/CIR/MissingFeatures.h"
19+
#include "llvm/ADT/APFloat.h"
1820
#include "llvm/ADT/STLExtras.h"
1921

2022
namespace clang::CIRGen {
@@ -229,6 +231,15 @@ class CIRGenBuilderTy : public cir::CIRBaseBuilderTy {
229231
cir::IntType getUInt32Ty() { return typeCache.UInt32Ty; }
230232
cir::IntType getUInt64Ty() { return typeCache.UInt64Ty; }
231233

234+
cir::ConstantOp getConstInt(mlir::Location loc, llvm::APSInt intVal);
235+
236+
cir::ConstantOp getConstInt(mlir::Location loc, llvm::APInt intVal);
237+
238+
cir::ConstantOp getConstInt(mlir::Location loc, mlir::Type t, uint64_t c);
239+
240+
cir::ConstantOp getConstFP(mlir::Location loc, mlir::Type t,
241+
llvm::APFloat fpVal);
242+
232243
bool isInt8Ty(mlir::Type i) {
233244
return i == typeCache.UInt8Ty || i == typeCache.SInt8Ty;
234245
}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
//
9+
// This contains code to emit Builtin calls as CIR or a function call to be
10+
// later resolved.
11+
//
12+
//===----------------------------------------------------------------------===//
13+
14+
#include "CIRGenCall.h"
15+
#include "CIRGenFunction.h"
16+
#include "CIRGenModule.h"
17+
#include "CIRGenValue.h"
18+
#include "mlir/IR/BuiltinAttributes.h"
19+
#include "mlir/IR/Value.h"
20+
#include "mlir/Support/LLVM.h"
21+
#include "clang/AST/Expr.h"
22+
#include "clang/AST/GlobalDecl.h"
23+
#include "llvm/Support/ErrorHandling.h"
24+
25+
using namespace clang;
26+
using namespace clang::CIRGen;
27+
28+
RValue CIRGenFunction::emitBuiltinExpr(const GlobalDecl &gd, unsigned builtinID,
29+
const CallExpr *e,
30+
ReturnValueSlot returnValue) {
31+
// See if we can constant fold this builtin. If so, don't emit it at all.
32+
// TODO: Extend this handling to all builtin calls that we can constant-fold.
33+
Expr::EvalResult result;
34+
if (e->isPRValue() && e->EvaluateAsRValue(result, cgm.getASTContext()) &&
35+
!result.hasSideEffects()) {
36+
if (result.Val.isInt()) {
37+
return RValue::get(builder.getConstInt(getLoc(e->getSourceRange()),
38+
result.Val.getInt()));
39+
}
40+
if (result.Val.isFloat()) {
41+
// Note: we are using result type of CallExpr to determine the type of
42+
// the constant. Classic codegen uses the result value to determine the
43+
// type. We feel it should be Ok to use expression type because it is
44+
// hard to imagine a builtin function evaluates to a value that
45+
// over/underflows its own defined type.
46+
mlir::Type type = convertType(e->getType());
47+
return RValue::get(builder.getConstFP(getLoc(e->getExprLoc()), type,
48+
result.Val.getFloat()));
49+
}
50+
}
51+
52+
mlir::Location loc = getLoc(e->getExprLoc());
53+
cgm.errorNYI(loc, "non constant foldable builtin calls");
54+
return getUndefRValue(e->getType());
55+
}

clang/lib/CIR/CodeGen/CIRGenCall.h

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,16 +44,25 @@ class CIRGenCalleeInfo {
4444
class CIRGenCallee {
4545
enum class SpecialKind : uintptr_t {
4646
Invalid,
47+
Builtin,
4748

48-
Last = Invalid,
49+
Last = Builtin,
50+
};
51+
52+
struct BuiltinInfoStorage {
53+
const clang::FunctionDecl *decl;
54+
unsigned id;
4955
};
5056

5157
SpecialKind kindOrFunctionPtr;
5258

5359
union {
5460
CIRGenCalleeInfo abstractInfo;
61+
BuiltinInfoStorage builtinInfo;
5562
};
5663

64+
explicit CIRGenCallee(SpecialKind kind) : kindOrFunctionPtr(kind) {}
65+
5766
public:
5867
CIRGenCallee() : kindOrFunctionPtr(SpecialKind::Invalid) {}
5968

@@ -69,6 +78,25 @@ class CIRGenCallee {
6978
return CIRGenCallee(abstractInfo, funcPtr);
7079
}
7180

81+
bool isBuiltin() const { return kindOrFunctionPtr == SpecialKind::Builtin; }
82+
83+
const clang::FunctionDecl *getBuiltinDecl() const {
84+
assert(isBuiltin());
85+
return builtinInfo.decl;
86+
}
87+
unsigned getBuiltinID() const {
88+
assert(isBuiltin());
89+
return builtinInfo.id;
90+
}
91+
92+
static CIRGenCallee forBuiltin(unsigned builtinID,
93+
const clang::FunctionDecl *builtinDecl) {
94+
CIRGenCallee result(SpecialKind::Builtin);
95+
result.builtinInfo.decl = builtinDecl;
96+
result.builtinInfo.id = builtinID;
97+
return result;
98+
}
99+
72100
bool isOrdinary() const {
73101
return uintptr_t(kindOrFunctionPtr) > uintptr_t(SpecialKind::Last);
74102
}

0 commit comments

Comments
 (0)