Skip to content

Commit 7293b5d

Browse files
committed
Merge from 'main' to 'sycl-web' (34 commits)
CONFLICT (content): Merge conflict in clang/lib/Driver/ToolChains/Clang.cpp
2 parents 9ae0cab + 41cece8 commit 7293b5d

File tree

120 files changed

+1913
-1186
lines changed

Some content is hidden

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

120 files changed

+1913
-1186
lines changed

clang/docs/LanguageExtensions.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1640,6 +1640,7 @@ Conditional ``explicit`` __cpp_conditional_explicit C+
16401640
``static operator()`` __cpp_static_call_operator C++23 C++03
16411641
Attributes on Lambda-Expressions C++23 C++11
16421642
Attributes on Structured Bindings __cpp_structured_bindings C++26 C++03
1643+
Packs in Structured Bindings __cpp_structured_bindings C++26 C++03
16431644
Static assert with user-generated message __cpp_static_assert >= 202306L C++26 C++11
16441645
Pack Indexing __cpp_pack_indexing C++26 C++03
16451646
``= delete ("should have a reason");`` __cpp_deleted_function C++26 C++03

clang/docs/ReleaseNotes.rst

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,8 @@ C++ Language Changes
7171
C++2c Feature Support
7272
^^^^^^^^^^^^^^^^^^^^^
7373

74+
- Implemented `P1061R10 Structured Bindings can introduce a Pack <https://wg21.link/P1061R10>`_.
75+
7476
C++23 Feature Support
7577
^^^^^^^^^^^^^^^^^^^^^
7678

@@ -168,6 +170,8 @@ Bug Fixes to C++ Support
168170
^^^^^^^^^^^^^^^^^^^^^^^^
169171

170172
- Clang is now better at keeping track of friend function template instance contexts. (#GH55509)
173+
- Clang now prints the correct instantiation context for diagnostics suppressed
174+
by template argument deduction.
171175
- The initialization kind of elements of structured bindings
172176
direct-list-initialized from an array is corrected to direct-initialization.
173177
- Clang no longer crashes when a coroutine is declared ``[[noreturn]]``. (#GH127327)
@@ -275,7 +279,7 @@ Code Completion
275279
Static Analyzer
276280
---------------
277281

278-
- Clang currently support extending lifetime of object bound to
282+
- Clang currently support extending lifetime of object bound to
279283
reference members of aggregates in CFG and ExprEngine, that are
280284
created from default member initializer.
281285

clang/docs/UsersManual.rst

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1681,19 +1681,27 @@ for more details.
16811681
permitted to produce more precise results than performing the same
16821682
operations separately.
16831683

1684-
The C standard permits intermediate floating-point results within an
1684+
The C and C++ standards permit intermediate floating-point results within an
16851685
expression to be computed with more precision than their type would
16861686
normally allow. This permits operation fusing, and Clang takes advantage
1687-
of this by default. This behavior can be controlled with the ``FP_CONTRACT``
1688-
and ``clang fp contract`` pragmas. Please refer to the pragma documentation
1689-
for a description of how the pragmas interact with this option.
1687+
of this by default (``on``). Fusion across statements is not compliant with
1688+
the C and C++ standards but can be enabled using ``-ffp-contract=fast``.
1689+
1690+
Fusion can be controlled with the ``FP_CONTRACT`` and ``clang fp contract``
1691+
pragmas. Please note that pragmas will be ingored with
1692+
``-ffp-contract=fast``, and refer to the pragma documentation for a
1693+
description of how the pragmas interact with the different ``-ffp-contract``
1694+
option values.
16901695

16911696
Valid values are:
16921697

1693-
* ``fast`` (fuse across statements disregarding pragmas, default for CUDA)
1694-
* ``on`` (fuse in the same statement unless dictated by pragmas, default for languages other than CUDA/HIP)
1695-
* ``off`` (never fuse)
1696-
* ``fast-honor-pragmas`` (fuse across statements unless dictated by pragmas, default for HIP)
1698+
* ``fast``: enable fusion across statements disregarding pragmas, breaking
1699+
compliance with the C and C++ standards (default for CUDA).
1700+
* ``on``: enable C and C++ standard complaint fusion in the same statement
1701+
unless dictated by pragmas (default for languages other than CUDA/HIP)
1702+
* ``off``: disable fusion
1703+
* ``fast-honor-pragmas``: fuse across statements unless dictated by pragmas
1704+
(default for HIP)
16971705

16981706
.. option:: -f[no-]honor-infinities
16991707

clang/include/clang/Driver/Options.td

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4110,11 +4110,15 @@ defm assumptions : BoolFOption<"assumptions",
41104110
"Disable codegen and compile-time checks for C++23's [[assume]] attribute">,
41114111
PosFlag<SetTrue>>;
41124112

4113+
4114+
let Visibility = [ClangOption, FlangOption] in {
41134115
def fvectorize : Flag<["-"], "fvectorize">, Group<f_Group>,
41144116
HelpText<"Enable the loop vectorization passes">;
41154117
def fno_vectorize : Flag<["-"], "fno-vectorize">, Group<f_Group>;
41164118
def : Flag<["-"], "ftree-vectorize">, Alias<fvectorize>;
41174119
def : Flag<["-"], "fno-tree-vectorize">, Alias<fno_vectorize>;
4120+
}
4121+
41184122
def fslp_vectorize : Flag<["-"], "fslp-vectorize">, Group<f_Group>,
41194123
HelpText<"Enable the superword-level parallelism vectorization passes">;
41204124
def fno_slp_vectorize : Flag<["-"], "fno-slp-vectorize">, Group<f_Group>;
@@ -7741,6 +7745,10 @@ def mlink_builtin_bitcode : Separate<["-"], "mlink-builtin-bitcode">,
77417745
def mlink_bitcode_file
77427746
: Separate<["-"], "mlink-bitcode-file">,
77437747
HelpText<"Link the given bitcode file before performing optimizations.">;
7748+
7749+
def vectorize_loops : Flag<["-"], "vectorize-loops">,
7750+
HelpText<"Run the Loop vectorization passes">,
7751+
MarshallingInfoFlag<CodeGenOpts<"VectorizeLoop">>;
77447752
} // let Visibility = [CC1Option, FC1Option]
77457753

77467754
let Visibility = [CC1Option] in {
@@ -7856,9 +7864,6 @@ defm link_builtin_bitcode_postopt: BoolMOption<"link-builtin-bitcode-postopt",
78567864
PosFlag<SetTrue, [], [ClangOption], "Link builtin bitcodes after the "
78577865
"optimization pipeline">,
78587866
NegFlag<SetFalse, [], [ClangOption]>>;
7859-
def vectorize_loops : Flag<["-"], "vectorize-loops">,
7860-
HelpText<"Run the Loop vectorization passes">,
7861-
MarshallingInfoFlag<CodeGenOpts<"VectorizeLoop">>;
78627867
def vectorize_slp : Flag<["-"], "vectorize-slp">,
78637868
HelpText<"Run the SLP vectorization passes">,
78647869
MarshallingInfoFlag<CodeGenOpts<"VectorizeSLP">>;

clang/include/clang/Sema/Sema.h

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1913,7 +1913,23 @@ class Sema final : public SemaBase {
19131913
/// '\#pragma clang attribute push' directives to the given declaration.
19141914
void AddPragmaAttributes(Scope *S, Decl *D);
19151915

1916-
void PrintPragmaAttributeInstantiationPoint();
1916+
using InstantiationContextDiagFuncRef =
1917+
llvm::function_ref<void(SourceLocation, PartialDiagnostic)>;
1918+
auto getDefaultDiagFunc() {
1919+
return [this](SourceLocation Loc, PartialDiagnostic PD) {
1920+
// This bypasses a lot of the filters in the diag engine, as it's
1921+
// to be used to attach notes to diagnostics which have already
1922+
// been filtered through.
1923+
DiagnosticBuilder Builder(Diags.Report(Loc, PD.getDiagID()));
1924+
PD.Emit(Builder);
1925+
};
1926+
}
1927+
1928+
void PrintPragmaAttributeInstantiationPoint(
1929+
InstantiationContextDiagFuncRef DiagFunc);
1930+
void PrintPragmaAttributeInstantiationPoint() {
1931+
PrintPragmaAttributeInstantiationPoint(getDefaultDiagFunc());
1932+
}
19171933

19181934
void DiagnoseUnterminatedPragmaAttribute();
19191935

@@ -13308,18 +13324,22 @@ class Sema final : public SemaBase {
1330813324
void pushCodeSynthesisContext(CodeSynthesisContext Ctx);
1330913325
void popCodeSynthesisContext();
1331013326

13311-
void PrintContextStack() {
13327+
void PrintContextStack(InstantiationContextDiagFuncRef DiagFunc) {
1331213328
if (!CodeSynthesisContexts.empty() &&
1331313329
CodeSynthesisContexts.size() != LastEmittedCodeSynthesisContextDepth) {
13314-
PrintInstantiationStack();
13330+
PrintInstantiationStack(DiagFunc);
1331513331
LastEmittedCodeSynthesisContextDepth = CodeSynthesisContexts.size();
1331613332
}
1331713333
if (PragmaAttributeCurrentTargetDecl)
13318-
PrintPragmaAttributeInstantiationPoint();
13334+
PrintPragmaAttributeInstantiationPoint(DiagFunc);
1331913335
}
13336+
void PrintContextStack() { PrintContextStack(getDefaultDiagFunc()); }
1332013337
/// Prints the current instantiation stack through a series of
1332113338
/// notes.
13322-
void PrintInstantiationStack();
13339+
void PrintInstantiationStack(InstantiationContextDiagFuncRef DiagFunc);
13340+
void PrintInstantiationStack() {
13341+
PrintInstantiationStack(getDefaultDiagFunc());
13342+
}
1332313343

1332413344
/// Determines whether we are currently in a context where
1332513345
/// template argument substitution failures are not considered

clang/lib/AST/APValue.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -390,7 +390,6 @@ APValue &APValue::operator=(const APValue &RHS) {
390390
if (this != &RHS)
391391
*this = APValue(RHS);
392392

393-
AllowConstexprUnknown = RHS.AllowConstexprUnknown;
394393
return *this;
395394
}
396395

clang/lib/CodeGen/CGBuiltin.cpp

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -908,24 +908,6 @@ static void emitSincosBuiltin(CodeGenFunction &CGF, const CallExpr *E,
908908
StoreCos->setMetadata(LLVMContext::MD_noalias, AliasScopeList);
909909
}
910910

911-
static llvm::Value *emitModfBuiltin(CodeGenFunction &CGF, const CallExpr *E,
912-
llvm::Intrinsic::ID IntrinsicID) {
913-
llvm::Value *Val = CGF.EmitScalarExpr(E->getArg(0));
914-
llvm::Value *IntPartDest = CGF.EmitScalarExpr(E->getArg(1));
915-
916-
llvm::Value *Call =
917-
CGF.Builder.CreateIntrinsic(IntrinsicID, {Val->getType()}, Val);
918-
919-
llvm::Value *FractionalResult = CGF.Builder.CreateExtractValue(Call, 0);
920-
llvm::Value *IntegralResult = CGF.Builder.CreateExtractValue(Call, 1);
921-
922-
QualType DestPtrType = E->getArg(1)->getType()->getPointeeType();
923-
LValue IntegralLV = CGF.MakeNaturalAlignAddrLValue(IntPartDest, DestPtrType);
924-
CGF.EmitStoreOfScalar(IntegralResult, IntegralLV);
925-
926-
return FractionalResult;
927-
}
928-
929911
/// EmitFAbs - Emit a call to @llvm.fabs().
930912
static Value *EmitFAbs(CodeGenFunction &CGF, Value *V) {
931913
Function *F = CGF.CGM.getIntrinsic(Intrinsic::fabs, V->getType());
@@ -4237,15 +4219,6 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl GD, unsigned BuiltinID,
42374219
case Builtin::BI__builtin_frexpf128:
42384220
case Builtin::BI__builtin_frexpf16:
42394221
return RValue::get(emitFrexpBuiltin(*this, E, Intrinsic::frexp));
4240-
case Builtin::BImodf:
4241-
case Builtin::BImodff:
4242-
case Builtin::BImodfl:
4243-
case Builtin::BI__builtin_modf:
4244-
case Builtin::BI__builtin_modff:
4245-
case Builtin::BI__builtin_modfl:
4246-
if (Builder.getIsFPConstrained())
4247-
break; // TODO: Emit constrained modf intrinsic once one exists.
4248-
return RValue::get(emitModfBuiltin(*this, E, Intrinsic::modf));
42494222
case Builtin::BI__builtin_isgreater:
42504223
case Builtin::BI__builtin_isgreaterequal:
42514224
case Builtin::BI__builtin_isless:

clang/lib/CodeGen/CodeGenTBAA.cpp

Lines changed: 41 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,42 @@ llvm::MDNode *CodeGenTBAA::getChar() {
8080
return Char;
8181
}
8282

83+
llvm::MDNode *CodeGenTBAA::getAnyPtr(unsigned PtrDepth) {
84+
assert(PtrDepth >= 1 && "Pointer must have some depth");
85+
86+
// Populate at least PtrDepth elements in AnyPtrs. These are the type nodes
87+
// for "any" pointers of increasing pointer depth, and are organized in the
88+
// hierarchy: any pointer <- any p2 pointer <- any p3 pointer <- ...
89+
//
90+
// Note that AnyPtrs[Idx] is actually the node for pointer depth (Idx+1),
91+
// since there is no node for pointer depth 0.
92+
//
93+
// These "any" pointer type nodes are used in pointer TBAA. The type node of
94+
// a concrete pointer type has the "any" pointer type node of appropriate
95+
// pointer depth as its parent. The "any" pointer type nodes are also used
96+
// directly for accesses to void pointers, or to specific pointers that we
97+
// conservatively do not distinguish in pointer TBAA (e.g. pointers to
98+
// members). Essentially, this establishes that e.g. void** can alias with
99+
// any type that can unify with T**, ignoring things like qualifiers. Here, T
100+
// is a variable that represents an arbitrary type, including pointer types.
101+
// As such, each depth is naturally a subtype of the previous depth, and thus
102+
// transitively of all previous depths.
103+
if (AnyPtrs.size() < PtrDepth) {
104+
AnyPtrs.reserve(PtrDepth);
105+
auto Size = Module.getDataLayout().getPointerSize();
106+
// Populate first element.
107+
if (AnyPtrs.empty())
108+
AnyPtrs.push_back(createScalarTypeNode("any pointer", getChar(), Size));
109+
// Populate further elements.
110+
for (size_t Idx = AnyPtrs.size(); Idx < PtrDepth; ++Idx) {
111+
auto Name = ("any p" + llvm::Twine(Idx + 1) + " pointer").str();
112+
AnyPtrs.push_back(createScalarTypeNode(Name, AnyPtrs[Idx - 1], Size));
113+
}
114+
}
115+
116+
return AnyPtrs[PtrDepth - 1];
117+
}
118+
83119
static bool TypeHasMayAlias(QualType QTy) {
84120
// Tagged types have declarations, and therefore may have attributes.
85121
if (auto *TD = QTy->getAsTagDecl())
@@ -202,9 +238,8 @@ llvm::MDNode *CodeGenTBAA::getTypeInfoHelper(const Type *Ty) {
202238
// they involve a significant representation difference. We don't
203239
// currently do so, however.
204240
if (Ty->isPointerType() || Ty->isReferenceType()) {
205-
llvm::MDNode *AnyPtr = createScalarTypeNode("any pointer", getChar(), Size);
206241
if (!CodeGenOpts.PointerTBAA)
207-
return AnyPtr;
242+
return getAnyPtr();
208243
// C++ [basic.lval]p11 permits objects to accessed through an l-value of
209244
// similar type. Two types are similar under C++ [conv.qual]p2 if the
210245
// decomposition of the types into pointers, member pointers, and arrays has
@@ -232,7 +267,7 @@ llvm::MDNode *CodeGenTBAA::getTypeInfoHelper(const Type *Ty) {
232267
// common idioms and there is no good alternative to re-write the code
233268
// without strict-aliasing violations.
234269
if (Ty->isVoidType())
235-
return AnyPtr;
270+
return getAnyPtr(PtrDepth);
236271

237272
assert(!isa<VariableArrayType>(Ty));
238273
// When the underlying type is a builtin type, we compute the pointee type
@@ -256,7 +291,7 @@ llvm::MDNode *CodeGenTBAA::getTypeInfoHelper(const Type *Ty) {
256291
// similar-types rule.
257292
const auto *RT = Ty->getAs<RecordType>();
258293
if (!RT)
259-
return AnyPtr;
294+
return getAnyPtr(PtrDepth);
260295

261296
// For unnamed structs or unions C's compatible types rule applies. Two
262297
// compatible types in different compilation units can have different
@@ -270,7 +305,7 @@ llvm::MDNode *CodeGenTBAA::getTypeInfoHelper(const Type *Ty) {
270305
// compatibility rule, but it doesn't matter because you can never have a
271306
// pointer to an anonymous struct or union.
272307
if (!RT->getDecl()->getDeclName())
273-
return AnyPtr;
308+
return getAnyPtr(PtrDepth);
274309

275310
// For non-builtin types use the mangled name of the canonical type.
276311
llvm::raw_svector_ostream TyOut(TyName);
@@ -281,7 +316,7 @@ llvm::MDNode *CodeGenTBAA::getTypeInfoHelper(const Type *Ty) {
281316
OutName += std::to_string(PtrDepth);
282317
OutName += " ";
283318
OutName += TyName;
284-
return createScalarTypeNode(OutName, AnyPtr, Size);
319+
return createScalarTypeNode(OutName, getAnyPtr(PtrDepth), Size);
285320
}
286321

287322
// Accesses to arrays are accesses to objects of their element types.

clang/lib/CodeGen/CodeGenTBAA.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ class CodeGenTBAA {
139139

140140
llvm::MDNode *Root;
141141
llvm::MDNode *Char;
142+
llvm::SmallVector<llvm::MDNode *, 4> AnyPtrs;
142143

143144
/// getRoot - This is the mdnode for the root of the metadata type graph
144145
/// for this translation unit.
@@ -148,6 +149,10 @@ class CodeGenTBAA {
148149
/// considered to be equivalent to it.
149150
llvm::MDNode *getChar();
150151

152+
/// getAnyPtr - This is the mdnode for any pointer type of (at least) the
153+
/// given pointer depth.
154+
llvm::MDNode *getAnyPtr(unsigned PtrDepth = 1);
155+
151156
/// CollectFields - Collect information about the fields of a type for
152157
/// !tbaa.struct metadata formation. Return false for an unsupported type.
153158
bool CollectFields(uint64_t BaseOffset,

clang/lib/Driver/ToolChains/Clang.cpp

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -537,39 +537,6 @@ static bool isSYCLOptimizationO2orHigher(const ArgList &Args) {
537537
return true;
538538
}
539539

540-
/// Vectorize at all optimization levels greater than 1 except for -Oz.
541-
/// For -Oz the loop vectorizer is disabled, while the slp vectorizer is
542-
/// enabled.
543-
static bool shouldEnableVectorizerAtOLevel(const ArgList &Args, bool isSlpVec) {
544-
if (Arg *A = Args.getLastArg(options::OPT_O_Group)) {
545-
if (A->getOption().matches(options::OPT_O4) ||
546-
A->getOption().matches(options::OPT_Ofast))
547-
return true;
548-
549-
if (A->getOption().matches(options::OPT_O0))
550-
return false;
551-
552-
assert(A->getOption().matches(options::OPT_O) && "Must have a -O flag");
553-
554-
// Vectorize -Os.
555-
StringRef S(A->getValue());
556-
if (S == "s")
557-
return true;
558-
559-
// Don't vectorize -Oz, unless it's the slp vectorizer.
560-
if (S == "z")
561-
return isSlpVec;
562-
563-
unsigned OptLevel = 0;
564-
if (S.getAsInteger(10, OptLevel))
565-
return false;
566-
567-
return OptLevel > 1;
568-
}
569-
570-
return false;
571-
}
572-
573540
/// Add -x lang to \p CmdArgs for \p Input.
574541
static void addDashXForInput(const ArgList &Args, const InputInfo &Input,
575542
ArgStringList &CmdArgs) {

clang/lib/Driver/ToolChains/CommonArgs.cpp

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3160,3 +3160,36 @@ void tools::renderCommonIntegerOverflowOptions(const ArgList &Args,
31603160
if (use_fwrapv_pointer)
31613161
CmdArgs.push_back("-fwrapv-pointer");
31623162
}
3163+
3164+
/// Vectorize at all optimization levels greater than 1 except for -Oz.
3165+
/// For -Oz the loop vectorizer is disabled, while the slp vectorizer is
3166+
/// enabled.
3167+
bool tools::shouldEnableVectorizerAtOLevel(const ArgList &Args, bool isSlpVec) {
3168+
if (Arg *A = Args.getLastArg(options::OPT_O_Group)) {
3169+
if (A->getOption().matches(options::OPT_O4) ||
3170+
A->getOption().matches(options::OPT_Ofast))
3171+
return true;
3172+
3173+
if (A->getOption().matches(options::OPT_O0))
3174+
return false;
3175+
3176+
assert(A->getOption().matches(options::OPT_O) && "Must have a -O flag");
3177+
3178+
// Vectorize -Os.
3179+
StringRef S(A->getValue());
3180+
if (S == "s")
3181+
return true;
3182+
3183+
// Don't vectorize -Oz, unless it's the slp vectorizer.
3184+
if (S == "z")
3185+
return isSlpVec;
3186+
3187+
unsigned OptLevel = 0;
3188+
if (S.getAsInteger(10, OptLevel))
3189+
return false;
3190+
3191+
return OptLevel > 1;
3192+
}
3193+
3194+
return false;
3195+
}

0 commit comments

Comments
 (0)