Skip to content

Commit af6a570

Browse files
committed
merge main into amd-staging
2 parents 394f9dd + 8dd160f commit af6a570

File tree

79 files changed

+2936
-262
lines changed

Some content is hidden

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

79 files changed

+2936
-262
lines changed

clang-tools-extra/clangd/IncludeFixer.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,6 @@ std::vector<Fix> IncludeFixer::fix(DiagnosticsEngine::Level DiagLevel,
8484
case diag::err_array_incomplete_or_sizeless_type:
8585
case diag::err_array_size_incomplete_type:
8686
case diag::err_asm_incomplete_type:
87-
case diag::err_assoc_type_incomplete:
8887
case diag::err_bad_cast_incomplete:
8988
case diag::err_call_function_incomplete_return:
9089
case diag::err_call_incomplete_argument:

clang/docs/ReleaseNotes.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,10 @@ C Language Changes
111111

112112
C2y Feature Support
113113
^^^^^^^^^^^^^^^^^^^
114+
- Implement `WG14 N3409 <https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3409.pdf>`_
115+
which removes UB around use of ``void`` expressions. In practice, this means
116+
that ``_Generic`` selection associations may now have ``void`` type, but it
117+
also removes UB with code like ``(void)(void)1;``.
114118
- Implemented `WG14 N3411 <https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3411.pdf>`_
115119
which allows a source file to not end with a newline character. This is still
116120
reported as a conforming extension in earlier language modes.

clang/include/clang/Basic/AttrDocs.td

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1116,10 +1116,10 @@ template instantiation, so the value for ``T::number`` is known.
11161116
def ExtVectorTypeDocs : Documentation {
11171117
let Category = DocCatFunction;
11181118
let Content = [{
1119-
The ext_vector_type(N) attribute specifies that a type is a vector with N
1119+
The ``ext_vector_type(N)`` attribute specifies that a type is a vector with N
11201120
elements, directly mapping to an LLVM vector type. Originally from OpenCL, it
1121-
allows element access the array subscript operator ``[]``, ``sN`` where ``N`` is
1122-
a hexadecimal value, or ``x``, ``y``, ``z``, ``w`` for graphics-style indexing.
1121+
allows element access the array subscript operator ``[]``, ``sN`` where N is
1122+
a hexadecimal value, or ``x, y, z, w`` for graphics-style indexing.
11231123
This attribute enables efficient SIMD operations and is usable in
11241124
general-purpose code.
11251125

@@ -1128,17 +1128,16 @@ general-purpose code.
11281128
template <typename T, uint32_t N>
11291129
constexpr T simd_reduce(T [[clang::ext_vector_type(N)]] v) {
11301130
static_assert((N & (N - 1)) == 0, "N must be a power of two");
1131-
if constexpr (N == 1) {
1131+
if constexpr (N == 1)
11321132
return v[0];
1133-
} else {
1134-
T [[clang::ext_vector_type(N / 2)]] reduced = v.hi + v.lo;
1135-
return simd_reduce(reduced);
1136-
}
1133+
else
1134+
return simd_reduce<T, N / 2>(v.hi + v.lo);
11371135
}
11381136

11391137
The vector type also supports swizzling up to sixteen elements. This can be done
1140-
using the object accessors. The OpenCL documentation lists the full list of
1141-
accepted values.
1138+
using the object accessors. The OpenCL documentation lists all of the accepted
1139+
values.
1140+
11421141
.. code-block:: c++
11431142

11441143
using f16_x16 = _Float16 __attribute__((ext_vector_type(16)));

clang/include/clang/Basic/DiagnosticSemaKinds.td

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10428,8 +10428,13 @@ def warn_type_safety_null_pointer_required : Warning<
1042810428
"specified %0 type tag requires a null pointer">, InGroup<TypeSafety>;
1042910429

1043010430
// Generic selections.
10431-
def err_assoc_type_incomplete : Error<
10432-
"type %0 in generic association incomplete">;
10431+
def ext_assoc_type_incomplete : Extension<
10432+
"incomplete type %0 in a '_Generic' association is a C2y extension">,
10433+
InGroup<C2y>;
10434+
def warn_c2y_compat_assoc_type_incomplete : Warning<
10435+
"use of incomplete type %0 in a '_Generic' association is incompatible with "
10436+
"C standards before C2y">,
10437+
InGroup<CPre2yCompat>, DefaultIgnore;
1043310438
def err_assoc_type_nonobject : Error<
1043410439
"type %0 in generic association not an object type">;
1043510440
def err_assoc_type_variably_modified : Error<

clang/include/clang/CIR/Dialect/Builder/CIRBaseBuilder.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ class CIRBaseBuilderTy : public mlir::OpBuilder {
2626
CIRBaseBuilderTy(mlir::MLIRContext &mlirContext)
2727
: mlir::OpBuilder(&mlirContext) {}
2828

29+
cir::ConstantOp getConstant(mlir::Location loc, mlir::TypedAttr attr) {
30+
return create<cir::ConstantOp>(loc, attr.getType(), attr);
31+
}
32+
2933
cir::ConstantOp getBool(bool state, mlir::Location loc) {
3034
return create<cir::ConstantOp>(loc, getBoolTy(), getCIRBoolAttr(state));
3135
}

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,20 @@ def CIR_BoolAttr : CIR_Attr<"Bool", "bool", [TypedAttrInterface]> {
5454
}];
5555
}
5656

57+
//===----------------------------------------------------------------------===//
58+
// ZeroAttr
59+
//===----------------------------------------------------------------------===//
60+
61+
def ZeroAttr : CIR_Attr<"Zero", "zero", [TypedAttrInterface]> {
62+
let summary = "Attribute to represent zero initialization";
63+
let description = [{
64+
The ZeroAttr is used to indicate zero initialization on structs.
65+
}];
66+
67+
let parameters = (ins AttributeSelfTypeParameter<"">:$type);
68+
let assemblyFormat = [{}];
69+
}
70+
5771
//===----------------------------------------------------------------------===//
5872
// UndefAttr
5973
//===----------------------------------------------------------------------===//

clang/include/clang/CIR/MissingFeatures.h

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,16 +41,17 @@ struct MissingFeatures {
4141
static bool supportComdat() { return false; }
4242

4343
// Load/store attributes
44-
static bool opLoadThreadLocal() { return false; }
44+
static bool opLoadStoreThreadLocal() { return false; }
4545
static bool opLoadEmitScalarRangeCheck() { return false; }
4646
static bool opLoadBooleanRepresentation() { return false; }
4747
static bool opLoadStoreTbaa() { return false; }
4848
static bool opLoadStoreMemOrder() { return false; }
4949
static bool opLoadStoreVolatile() { return false; }
5050
static bool opLoadStoreAlignment() { return false; }
51+
static bool opLoadStoreAtomic() { return false; }
52+
static bool opLoadStoreObjC() { return false; }
5153

5254
// AllocaOp handling
53-
static bool opAllocaVarDeclContext() { return false; }
5455
static bool opAllocaStaticLocal() { return false; }
5556
static bool opAllocaNonGC() { return false; }
5657
static bool opAllocaImpreciseLifetime() { return false; }
@@ -61,6 +62,7 @@ struct MissingFeatures {
6162
static bool opAllocaReference() { return false; }
6263
static bool opAllocaAnnotations() { return false; }
6364
static bool opAllocaDynAllocSize() { return false; }
65+
static bool opAllocaCaptureByInit() { return false; }
6466

6567
// FuncOp handling
6668
static bool opFuncOpenCLKernelMetadata() { return false; }
@@ -76,6 +78,10 @@ struct MissingFeatures {
7678
static bool constructABIArgDirectExtend() { return false; }
7779
static bool opGlobalViewAttr() { return false; }
7880
static bool lowerModeOptLevel() { return false; }
81+
static bool opTBAA() { return false; }
82+
static bool objCLifetime() { return false; }
83+
static bool emitNullabilityCheck() { return false; }
84+
static bool astVarDeclInterface() { return false; }
7985
};
8086

8187
} // namespace cir
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
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+
// A helper class for emitting expressions and values as cir::ConstantOp
10+
// and as initializers for global variables.
11+
//
12+
// Note: this is based on clang's LLVM IR codegen in ConstantEmitter.h, reusing
13+
// this class interface makes it easier move forward with bringing CIR codegen
14+
// to completion.
15+
//
16+
//===----------------------------------------------------------------------===//
17+
18+
#ifndef CLANG_LIB_CIR_CODEGEN_CIRGENCONSTANTEMITTER_H
19+
#define CLANG_LIB_CIR_CODEGEN_CIRGENCONSTANTEMITTER_H
20+
21+
#include "CIRGenFunction.h"
22+
#include "CIRGenModule.h"
23+
#include "llvm/ADT/SmallVector.h"
24+
25+
namespace clang::CIRGen {
26+
27+
class ConstantEmitter {
28+
public:
29+
CIRGenModule &cgm;
30+
const CIRGenFunction *cgf;
31+
32+
private:
33+
bool abstract = false;
34+
35+
/// Whether we're in a constant context.
36+
bool inConstantContext = false;
37+
38+
public:
39+
/// Initialize this emission in the context of the given function.
40+
/// Use this if the expression might contain contextual references like
41+
/// block addresses or PredefinedExprs.
42+
ConstantEmitter(CIRGenFunction &cgf) : cgm(cgf.cgm), cgf(&cgf) {}
43+
44+
ConstantEmitter(const ConstantEmitter &other) = delete;
45+
ConstantEmitter &operator=(const ConstantEmitter &other) = delete;
46+
47+
// All of the "abstract" emission methods below permit the emission to
48+
// be immediately discarded without finalizing anything. Therefore, they
49+
// must also promise not to do anything that will, in the future, require
50+
// finalization:
51+
//
52+
// - using the CGF (if present) for anything other than establishing
53+
// semantic context; for example, an expression with ignored
54+
// side-effects must not be emitted as an abstract expression
55+
//
56+
// - doing anything that would not be safe to duplicate within an
57+
// initializer or to propagate to another context; for example,
58+
// side effects, or emitting an initialization that requires a
59+
// reference to its current location.
60+
mlir::Attribute emitForMemory(mlir::Attribute c, QualType t);
61+
62+
/// Emit the result of the given expression as an abstract constant,
63+
/// asserting that it succeeded. This is only safe to do when the
64+
/// expression is known to be a constant expression with either a fairly
65+
/// simple type or a known simple form.
66+
mlir::Attribute emitAbstract(SourceLocation loc, const APValue &value,
67+
QualType t);
68+
69+
mlir::Attribute tryEmitConstantExpr(const ConstantExpr *CE);
70+
71+
// These are private helper routines of the constant emitter that
72+
// can't actually be private because things are split out into helper
73+
// functions and classes.
74+
75+
mlir::Attribute tryEmitPrivateForVarInit(const VarDecl &d);
76+
77+
mlir::Attribute tryEmitPrivate(const APValue &value, QualType destType);
78+
mlir::Attribute tryEmitPrivateForMemory(const APValue &value, QualType t);
79+
80+
/// Try to emit the initializer of the given declaration as an abstract
81+
/// constant.
82+
mlir::Attribute tryEmitAbstractForInitializer(const VarDecl &d);
83+
84+
private:
85+
class AbstractStateRAII {
86+
ConstantEmitter &emitter;
87+
bool oldValue;
88+
89+
public:
90+
AbstractStateRAII(ConstantEmitter &emitter, bool value)
91+
: emitter(emitter), oldValue(emitter.abstract) {
92+
emitter.abstract = value;
93+
}
94+
~AbstractStateRAII() { emitter.abstract = oldValue; }
95+
};
96+
};
97+
98+
} // namespace clang::CIRGen
99+
100+
#endif // CLANG_LIB_CIR_CODEGEN_CIRGENCONSTANTEMITTER_H

0 commit comments

Comments
 (0)