Skip to content

Commit 59b80dc

Browse files
authored
Merge branch 'main' into add_orcb_optimizations
2 parents c1e0f3f + 73ad416 commit 59b80dc

File tree

413 files changed

+16353
-21957
lines changed

Some content is hidden

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

413 files changed

+16353
-21957
lines changed

.ci/generate-buildkite-pipeline-premerge

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,9 @@ function keep-modified-projects() {
191191
}
192192

193193
function check-targets() {
194+
# Do not use "check-all" here because if there is "check-all" plus a
195+
# project specific target like "check-clang", that project's tests
196+
# will be run twice.
194197
projects=${@}
195198
for project in ${projects}; do
196199
case ${project} in
@@ -216,7 +219,7 @@ function check-targets() {
216219
echo "check-lldb"
217220
;;
218221
pstl)
219-
echo "check-all"
222+
# Currently we do not run pstl tests in CI.
220223
;;
221224
libclc)
222225
# Currently there is no testing for libclc.

clang-tools-extra/clang-apply-replacements/lib/Tooling/ApplyReplacements.cpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -148,11 +148,8 @@ groupReplacements(const TUReplacements &TUs, const TUDiagnostics &TUDs,
148148

149149
if (auto Entry = SM.getFileManager().getOptionalFileRef(Path)) {
150150
if (SourceTU) {
151-
auto &Replaces = DiagReplacements[*Entry];
152-
auto It = Replaces.find(R);
153-
if (It == Replaces.end())
154-
Replaces.emplace(R, SourceTU);
155-
else if (It->second != SourceTU)
151+
auto [It, Inserted] = DiagReplacements[*Entry].try_emplace(R, SourceTU);
152+
if (!Inserted && It->second != SourceTU)
156153
// This replacement is a duplicate of one suggested by another TU.
157154
return;
158155
}

clang-tools-extra/clang-change-namespace/ChangeNamespace.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -606,9 +606,8 @@ void ChangeNamespaceTool::run(
606606
Result.Nodes.getNodeAs<DeclRefExpr>("func_ref")) {
607607
// If this reference has been processed as a function call, we do not
608608
// process it again.
609-
if (ProcessedFuncRefs.count(FuncRef))
609+
if (!ProcessedFuncRefs.insert(FuncRef).second)
610610
return;
611-
ProcessedFuncRefs.insert(FuncRef);
612611
const auto *Func = Result.Nodes.getNodeAs<FunctionDecl>("func_decl");
613612
assert(Func);
614613
const auto *Context = Result.Nodes.getNodeAs<Decl>("dc");

clang-tools-extra/clang-tidy/bugprone/ForwardDeclarationNamespaceCheck.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,12 +146,13 @@ void ForwardDeclarationNamespaceCheck::onEndOfTranslationUnit() {
146146
}
147147
// Check if a definition in another namespace exists.
148148
const auto DeclName = CurDecl->getName();
149-
if (!DeclNameToDefinitions.contains(DeclName)) {
149+
auto It = DeclNameToDefinitions.find(DeclName);
150+
if (It == DeclNameToDefinitions.end()) {
150151
continue; // No definition in this translation unit, we can skip it.
151152
}
152153
// Make a warning for each definition with the same name (in other
153154
// namespaces).
154-
const auto &Definitions = DeclNameToDefinitions[DeclName];
155+
const auto &Definitions = It->second;
155156
for (const auto *Def : Definitions) {
156157
diag(CurDecl->getLocation(),
157158
"no definition found for %0, but a definition with "

clang/docs/ReleaseNotes.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,9 @@ C++23 Feature Support
171171
^^^^^^^^^^^^^^^^^^^^^
172172
- Removed the restriction to literal types in constexpr functions in C++23 mode.
173173

174+
- Extend lifetime of temporaries in mem-default-init for P2718R0. Clang now fully
175+
supports `P2718R0 Lifetime extension in range-based for loops <https://wg21.link/P2718R0>`_.
176+
174177
C++20 Feature Support
175178
^^^^^^^^^^^^^^^^^^^^^
176179

clang/include/clang/AST/Attr.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,23 @@ class InheritableParamAttr : public InheritableAttr {
197197
}
198198
};
199199

200+
class InheritableParamOrStmtAttr : public InheritableParamAttr {
201+
protected:
202+
InheritableParamOrStmtAttr(ASTContext &Context,
203+
const AttributeCommonInfo &CommonInfo,
204+
attr::Kind AK, bool IsLateParsed,
205+
bool InheritEvenIfAlreadyPresent)
206+
: InheritableParamAttr(Context, CommonInfo, AK, IsLateParsed,
207+
InheritEvenIfAlreadyPresent) {}
208+
209+
public:
210+
// Implement isa/cast/dyncast/etc.
211+
static bool classof(const Attr *A) {
212+
return A->getKind() >= attr::FirstInheritableParamOrStmtAttr &&
213+
A->getKind() <= attr::LastInheritableParamOrStmtAttr;
214+
}
215+
};
216+
200217
class HLSLAnnotationAttr : public InheritableAttr {
201218
protected:
202219
HLSLAnnotationAttr(ASTContext &Context, const AttributeCommonInfo &CommonInfo,

clang/include/clang/Basic/Attr.td

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -759,6 +759,11 @@ class TargetSpecificAttr<TargetSpec target> {
759759
/// redeclarations, even when it's written on a parameter.
760760
class InheritableParamAttr : InheritableAttr;
761761

762+
/// A attribute that is either a declaration attribute or a statement attribute,
763+
/// and if used as a declaration attribute, is inherited by later
764+
/// redeclarations, even when it's written on a parameter.
765+
class InheritableParamOrStmtAttr : InheritableParamAttr;
766+
762767
/// An attribute which changes the ABI rules for a specific parameter.
763768
class ParameterABIAttr : InheritableParamAttr {
764769
let Subjects = SubjectList<[ParmVar]>;
@@ -928,7 +933,7 @@ def AnalyzerNoReturn : InheritableAttr {
928933
let Documentation = [Undocumented];
929934
}
930935

931-
def Annotate : InheritableParamAttr {
936+
def Annotate : InheritableParamOrStmtAttr {
932937
let Spellings = [Clang<"annotate">];
933938
let Args = [StringArgument<"Annotation">, VariadicExprArgument<"Args">];
934939
// Ensure that the annotate attribute can be used with

clang/include/clang/Basic/Builtins.td

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4745,6 +4745,12 @@ def HLSLCross: LangBuiltin<"HLSL_LANG"> {
47454745
let Prototype = "void(...)";
47464746
}
47474747

4748+
def HLSLDegrees : LangBuiltin<"HLSL_LANG"> {
4749+
let Spellings = ["__builtin_hlsl_elementwise_degrees"];
4750+
let Attributes = [NoThrow, Const];
4751+
let Prototype = "void(...)";
4752+
}
4753+
47484754
def HLSLDotProduct : LangBuiltin<"HLSL_LANG"> {
47494755
let Spellings = ["__builtin_hlsl_dot"];
47504756
let Attributes = [NoThrow, Const];

clang/include/clang/Basic/CodeGenOptions.def

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,8 @@ CODEGENOPT(XRayIgnoreLoops , 1, 0)
136136
///< Emit the XRay function index section.
137137
CODEGENOPT(XRayFunctionIndex , 1, 1)
138138

139+
///< Set when -fxray-shared is enabled
140+
CODEGENOPT(XRayShared , 1, 0)
139141

140142
///< Set the minimum number of instructions in a function to determine selective
141143
///< XRay instrumentation.

clang/include/clang/Driver/Options.td

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2946,6 +2946,11 @@ def fxray_selected_function_group :
29462946
HelpText<"When using -fxray-function-groups, select which group of functions to instrument. Valid range is 0 to fxray-function-groups - 1">,
29472947
MarshallingInfoInt<CodeGenOpts<"XRaySelectedFunctionGroup">, "0">;
29482948

2949+
defm xray_shared : BoolFOption<"xray-shared",
2950+
CodeGenOpts<"XRayShared">, DefaultFalse,
2951+
PosFlag<SetTrue, [], [ClangOption, CC1Option],
2952+
"Enable shared library instrumentation with XRay">,
2953+
NegFlag<SetFalse>>;
29492954

29502955
defm fine_grained_bitfield_accesses : BoolOption<"f", "fine-grained-bitfield-accesses",
29512956
CodeGenOpts<"FineGrainedBitfieldAccesses">, DefaultFalse,

clang/include/clang/Driver/XRayArgs.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ class XRayArgs {
2727
XRayInstrSet InstrumentationBundle;
2828
llvm::opt::Arg *XRayInstrument = nullptr;
2929
bool XRayRT = true;
30+
bool XRayShared = false;
3031

3132
public:
3233
/// Parses the XRay arguments from an argument list.
@@ -35,6 +36,9 @@ class XRayArgs {
3536
llvm::opt::ArgStringList &CmdArgs, types::ID InputType) const;
3637

3738
bool needsXRayRt() const { return XRayInstrument && XRayRT; }
39+
bool needsXRayDSORt() const {
40+
return XRayInstrument && XRayRT && XRayShared;
41+
}
3842
llvm::ArrayRef<std::string> modeList() const { return Modes; }
3943
XRayInstrSet instrumentationBundle() const { return InstrumentationBundle; }
4044
};

clang/include/clang/Sema/Sema.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4528,9 +4528,10 @@ class Sema final : public SemaBase {
45284528
/// declaration.
45294529
void AddAlignValueAttr(Decl *D, const AttributeCommonInfo &CI, Expr *E);
45304530

4531-
/// AddAnnotationAttr - Adds an annotation Annot with Args arguments to D.
4532-
void AddAnnotationAttr(Decl *D, const AttributeCommonInfo &CI,
4533-
StringRef Annot, MutableArrayRef<Expr *> Args);
4531+
/// CreateAnnotationAttr - Creates an annotation Annot with Args arguments.
4532+
Attr *CreateAnnotationAttr(const AttributeCommonInfo &CI, StringRef Annot,
4533+
MutableArrayRef<Expr *> Args);
4534+
Attr *CreateAnnotationAttr(const ParsedAttr &AL);
45344535

45354536
bool checkMSInheritanceAttrOnDefinition(CXXRecordDecl *RD, SourceRange Range,
45364537
bool BestCase,

clang/lib/AST/ByteCode/Compiler.cpp

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2869,6 +2869,11 @@ bool Compiler<Emitter>::VisitPredefinedExpr(const PredefinedExpr *E) {
28692869
if (DiscardResult)
28702870
return true;
28712871

2872+
if (!Initializing) {
2873+
unsigned StringIndex = P.createGlobalString(E->getFunctionName(), E);
2874+
return this->emitGetPtrGlobal(StringIndex, E);
2875+
}
2876+
28722877
return this->delegate(E->getFunctionName());
28732878
}
28742879

@@ -6006,6 +6011,9 @@ bool Compiler<Emitter>::visitDeclRef(const ValueDecl *D, const Expr *E) {
60066011

60076012
return this->emitGetPtrParam(It->second.Offset, E);
60086013
}
6014+
6015+
if (D->getType()->isReferenceType())
6016+
return false; // FIXME: Do we need to emit InvalidDeclRef?
60096017
}
60106018

60116019
// In case we need to re-visit a declaration.
@@ -6042,9 +6050,7 @@ bool Compiler<Emitter>::visitDeclRef(const ValueDecl *D, const Expr *E) {
60426050
const auto typeShouldBeVisited = [&](QualType T) -> bool {
60436051
if (T.isConstant(Ctx.getASTContext()))
60446052
return true;
6045-
if (const auto *RT = T->getAs<ReferenceType>())
6046-
return RT->getPointeeType().isConstQualified();
6047-
return false;
6053+
return T->isReferenceType();
60486054
};
60496055

60506056
// DecompositionDecls are just proxies for us.
@@ -6060,9 +6066,12 @@ bool Compiler<Emitter>::visitDeclRef(const ValueDecl *D, const Expr *E) {
60606066
// other words, we're evaluating the initializer, just to know if we can
60616067
// evaluate the initializer.
60626068
if (VD->isLocalVarDecl() && typeShouldBeVisited(VD->getType()) &&
6063-
VD->getInit() && !VD->getInit()->isValueDependent() &&
6064-
VD->evaluateValue())
6065-
return revisit(VD);
6069+
VD->getInit() && !VD->getInit()->isValueDependent()) {
6070+
6071+
if (VD->evaluateValue())
6072+
return revisit(VD);
6073+
return this->emitInvalidDeclRef(cast<DeclRefExpr>(E), E);
6074+
}
60666075
}
60676076
} else {
60686077
if (const auto *VD = dyn_cast<VarDecl>(D);

clang/lib/AST/ByteCode/InterpBuiltin.cpp

Lines changed: 71 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ static T getParam(const InterpFrame *Frame, unsigned Index) {
3838
return Frame->getParam<T>(Offset);
3939
}
4040

41-
// static APSInt getAPSIntParam(InterpStack &Stk, size_t Offset = 0) {
4241
static APSInt getAPSIntParam(const InterpFrame *Frame, unsigned Index) {
4342
APSInt R;
4443
unsigned Offset = Frame->getFunction()->getParamOffset(Index);
@@ -1162,6 +1161,71 @@ static bool interp__builtin_is_aligned_up_down(InterpState &S, CodePtr OpPC,
11621161
return false;
11631162
}
11641163

1164+
/// __builtin_assume_aligned(Ptr, Alignment[, ExtraOffset])
1165+
static bool interp__builtin_assume_aligned(InterpState &S, CodePtr OpPC,
1166+
const InterpFrame *Frame,
1167+
const Function *Func,
1168+
const CallExpr *Call) {
1169+
assert(Call->getNumArgs() == 2 || Call->getNumArgs() == 3);
1170+
1171+
// Might be called with function pointers in C.
1172+
std::optional<PrimType> PtrT = S.Ctx.classify(Call->getArg(0));
1173+
if (PtrT != PT_Ptr)
1174+
return false;
1175+
1176+
unsigned ArgSize = callArgSize(S, Call);
1177+
const Pointer &Ptr = S.Stk.peek<Pointer>(ArgSize);
1178+
std::optional<APSInt> ExtraOffset;
1179+
APSInt Alignment;
1180+
if (Call->getNumArgs() == 2) {
1181+
Alignment = peekToAPSInt(S.Stk, *S.Ctx.classify(Call->getArg(1)));
1182+
} else {
1183+
PrimType AlignmentT = *S.Ctx.classify(Call->getArg(1));
1184+
PrimType ExtraOffsetT = *S.Ctx.classify(Call->getArg(2));
1185+
Alignment = peekToAPSInt(S.Stk, *S.Ctx.classify(Call->getArg(1)),
1186+
align(primSize(AlignmentT)) +
1187+
align(primSize(ExtraOffsetT)));
1188+
ExtraOffset = peekToAPSInt(S.Stk, *S.Ctx.classify(Call->getArg(2)));
1189+
}
1190+
1191+
CharUnits Align = CharUnits::fromQuantity(Alignment.getZExtValue());
1192+
1193+
// If there is a base object, then it must have the correct alignment.
1194+
if (Ptr.isBlockPointer()) {
1195+
CharUnits BaseAlignment;
1196+
if (const auto *VD = Ptr.getDeclDesc()->asValueDecl())
1197+
BaseAlignment = S.getASTContext().getDeclAlign(VD);
1198+
else if (const auto *E = Ptr.getDeclDesc()->asExpr())
1199+
BaseAlignment = GetAlignOfExpr(S.getASTContext(), E, UETT_AlignOf);
1200+
1201+
if (BaseAlignment < Align) {
1202+
S.CCEDiag(Call->getArg(0),
1203+
diag::note_constexpr_baa_insufficient_alignment)
1204+
<< 0 << BaseAlignment.getQuantity() << Align.getQuantity();
1205+
return false;
1206+
}
1207+
}
1208+
1209+
APValue AV = Ptr.toAPValue(S.getASTContext());
1210+
CharUnits AVOffset = AV.getLValueOffset();
1211+
if (ExtraOffset)
1212+
AVOffset -= CharUnits::fromQuantity(ExtraOffset->getZExtValue());
1213+
if (AVOffset.alignTo(Align) != AVOffset) {
1214+
if (Ptr.isBlockPointer())
1215+
S.CCEDiag(Call->getArg(0),
1216+
diag::note_constexpr_baa_insufficient_alignment)
1217+
<< 1 << AVOffset.getQuantity() << Align.getQuantity();
1218+
else
1219+
S.CCEDiag(Call->getArg(0),
1220+
diag::note_constexpr_baa_value_insufficient_alignment)
1221+
<< AVOffset.getQuantity() << Align.getQuantity();
1222+
return false;
1223+
}
1224+
1225+
S.Stk.push<Pointer>(Ptr);
1226+
return true;
1227+
}
1228+
11651229
static bool interp__builtin_ia32_bextr(InterpState &S, CodePtr OpPC,
11661230
const InterpFrame *Frame,
11671231
const Function *Func,
@@ -1287,7 +1351,7 @@ static bool interp__builtin_ia32_addcarry_subborrow(InterpState &S,
12871351
const InterpFrame *Frame,
12881352
const Function *Func,
12891353
const CallExpr *Call) {
1290-
if (!Call->getArg(0)->getType()->isIntegerType() ||
1354+
if (Call->getNumArgs() != 4 || !Call->getArg(0)->getType()->isIntegerType() ||
12911355
!Call->getArg(1)->getType()->isIntegerType() ||
12921356
!Call->getArg(2)->getType()->isIntegerType())
12931357
return false;
@@ -1905,6 +1969,11 @@ bool InterpretBuiltin(InterpState &S, CodePtr OpPC, const Function *F,
19051969
return false;
19061970
break;
19071971

1972+
case Builtin::BI__builtin_assume_aligned:
1973+
if (!interp__builtin_assume_aligned(S, OpPC, Frame, F, Call))
1974+
return false;
1975+
break;
1976+
19081977
case clang::X86::BI__builtin_ia32_bextr_u32:
19091978
case clang::X86::BI__builtin_ia32_bextr_u64:
19101979
case clang::X86::BI__builtin_ia32_bextri_u32:

clang/lib/AST/ByteCode/Pointer.cpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -253,11 +253,6 @@ APValue Pointer::toAPValue(const ASTContext &ASTCtx) const {
253253
}
254254
}
255255

256-
// FIXME(perf): We compute the lvalue path above, but we can't supply it
257-
// for dummy pointers (that causes crashes later in CheckConstantExpression).
258-
if (isDummy())
259-
Path.clear();
260-
261256
// We assemble the LValuePath starting from the innermost pointer to the
262257
// outermost one. SO in a.b.c, the first element in Path will refer to
263258
// the field 'c', while later code expects it to refer to 'a'.

clang/lib/AST/ByteCode/Program.cpp

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ const void *Program::getNativePointer(unsigned Idx) {
3333
return NativePointers[Idx];
3434
}
3535

36-
unsigned Program::createGlobalString(const StringLiteral *S) {
36+
unsigned Program::createGlobalString(const StringLiteral *S, const Expr *Base) {
3737
const size_t CharWidth = S->getCharByteWidth();
3838
const size_t BitWidth = CharWidth * Ctx.getCharBit();
3939

@@ -52,12 +52,15 @@ unsigned Program::createGlobalString(const StringLiteral *S) {
5252
llvm_unreachable("unsupported character width");
5353
}
5454

55+
if (!Base)
56+
Base = S;
57+
5558
// Create a descriptor for the string.
56-
Descriptor *Desc =
57-
allocateDescriptor(S, CharType, Descriptor::GlobalMD, S->getLength() + 1,
58-
/*isConst=*/true,
59-
/*isTemporary=*/false,
60-
/*isMutable=*/false);
59+
Descriptor *Desc = allocateDescriptor(Base, CharType, Descriptor::GlobalMD,
60+
S->getLength() + 1,
61+
/*isConst=*/true,
62+
/*isTemporary=*/false,
63+
/*isMutable=*/false);
6164

6265
// Allocate storage for the string.
6366
// The byte length does not include the null terminator.

clang/lib/AST/ByteCode/Program.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,8 @@ class Program final {
6464
const void *getNativePointer(unsigned Idx);
6565

6666
/// Emits a string literal among global data.
67-
unsigned createGlobalString(const StringLiteral *S);
67+
unsigned createGlobalString(const StringLiteral *S,
68+
const Expr *Base = nullptr);
6869

6970
/// Returns a pointer to a global.
7071
Pointer getPtrGlobal(unsigned Idx) const;

0 commit comments

Comments
 (0)