Skip to content

Commit 150f92d

Browse files
committed
merge main into amd-staging
2 parents 221033c + 9b00a58 commit 150f92d

File tree

128 files changed

+8677
-2023
lines changed

Some content is hidden

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

128 files changed

+8677
-2023
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -525,6 +525,9 @@ Improvements to Clang's diagnostics
525525
- The :doc:`ThreadSafetyAnalysis` attributes ``ACQUIRED_BEFORE(...)`` and
526526
``ACQUIRED_AFTER(...)`` have been moved to the stable feature set and no
527527
longer require ``-Wthread-safety-beta`` to be used.
528+
- The :doc:`ThreadSafetyAnalysis` gains basic alias-analysis of capability
529+
pointers under ``-Wthread-safety-beta`` (still experimental), which reduces
530+
both false positives but also false negatives through more precise analysis.
528531

529532
Improvements to Clang's time-trace
530533
----------------------------------
@@ -554,6 +557,8 @@ Bug Fixes in This Version
554557
- Builtin elementwise operators now accept vector arguments that have different
555558
qualifiers on their elements. For example, vector of 4 ``const float`` values
556559
and vector of 4 ``float`` values. (#GH155405)
560+
- Fixed a failed assertion with a negative limit parameter value inside of
561+
``__has_embed``. (#GH157842)
557562

558563
Bug Fixes to Compiler Builtins
559564
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

clang/include/clang/Analysis/Analyses/ThreadSafetyCommon.h

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
#include "llvm/ADT/PointerUnion.h"
3636
#include "llvm/ADT/SmallVector.h"
3737
#include "llvm/Support/Casting.h"
38+
#include <functional>
3839
#include <sstream>
3940
#include <string>
4041
#include <utility>
@@ -386,6 +387,11 @@ class SExprBuilder {
386387
SelfVar->setKind(til::Variable::VK_SFun);
387388
}
388389

390+
// Create placeholder for this: we don't know the VarDecl on construction yet.
391+
til::LiteralPtr *createThisPlaceholder() {
392+
return new (Arena) til::LiteralPtr(nullptr);
393+
}
394+
389395
// Translate a clang expression in an attribute to a til::SExpr.
390396
// Constructs the context from D, DeclExp, and SelfDecl.
391397
CapabilityExpr translateAttrExpr(const Expr *AttrExp, const NamedDecl *D,
@@ -394,8 +400,8 @@ class SExprBuilder {
394400

395401
CapabilityExpr translateAttrExpr(const Expr *AttrExp, CallingContext *Ctx);
396402

397-
// Translate a variable reference.
398-
til::LiteralPtr *createVariable(const VarDecl *VD);
403+
// Translate a VarDecl to its canonical TIL expression.
404+
til::SExpr *translateVariable(const VarDecl *VD, CallingContext *Ctx);
399405

400406
// Translate a clang statement or expression to a TIL expression.
401407
// Also performs substitution of variables; Ctx provides the context.
@@ -412,6 +418,10 @@ class SExprBuilder {
412418
const til::SCFG *getCFG() const { return Scfg; }
413419
til::SCFG *getCFG() { return Scfg; }
414420

421+
void setLookupLocalVarExpr(std::function<const Expr *(const NamedDecl *)> F) {
422+
LookupLocalVarExpr = std::move(F);
423+
}
424+
415425
private:
416426
// We implement the CFGVisitor API
417427
friend class CFGWalker;
@@ -445,6 +455,7 @@ class SExprBuilder {
445455
const AbstractConditionalOperator *C, CallingContext *Ctx);
446456

447457
til::SExpr *translateDeclStmt(const DeclStmt *S, CallingContext *Ctx);
458+
til::SExpr *translateStmtExpr(const StmtExpr *SE, CallingContext *Ctx);
448459

449460
// Map from statements in the clang CFG to SExprs in the til::SCFG.
450461
using StatementMap = llvm::DenseMap<const Stmt *, til::SExpr *>;
@@ -531,6 +542,11 @@ class SExprBuilder {
531542
std::vector<til::Phi *> IncompleteArgs;
532543
til::BasicBlock *CurrentBB = nullptr;
533544
BlockInfo *CurrentBlockInfo = nullptr;
545+
546+
// Recursion guard.
547+
llvm::DenseSet<const ValueDecl *> VarsBeingTranslated;
548+
// Context-dependent lookup of currently valid definitions of local variables.
549+
std::function<const Expr *(const NamedDecl *)> LookupLocalVarExpr;
534550
};
535551

536552
#ifndef NDEBUG

clang/include/clang/Basic/AttrDocs.td

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8367,6 +8367,23 @@ flag.
83678367
}];
83688368
}
83698369

8370+
def DocHLSLSemantics : DocumentationCategory<"HLSL Semantics"> {
8371+
let Content = [{
8372+
A semantic is a string attached to a shader input or output that conveys
8373+
information about the intended use of a parameter. Semantics are required on
8374+
all variables passed between shader stages. The syntax for adding a semantic
8375+
to a shader variable is shown here (Variable Syntax (DirectX HLSL)).
8376+
8377+
In general, data passed between pipeline stages is completely generic and is
8378+
not uniquely interpreted by the system; arbitrary semantics are allowed which
8379+
have no special meaning. Parameters (in Direct3D 10 and later) which contain
8380+
these special semantics are referred to as System-Value Semantics.
8381+
8382+
More information is available here:
8383+
https://learn.microsoft.com/en-us/windows/win32/direct3dhlsl/dx-graphics-hlsl-semantics
8384+
}];
8385+
}
8386+
83708387
def WaveSizeDocs : Documentation {
83718388
let Category = DocCatFunction;
83728389
let Content = [{
@@ -8604,7 +8621,7 @@ randomized.
86048621
}
86058622

86068623
def HLSLSV_GroupThreadIDDocs : Documentation {
8607-
let Category = DocCatFunction;
8624+
let Category = DocHLSLSemantics;
86088625
let Content = [{
86098626
The ``SV_GroupThreadID`` semantic, when applied to an input parameter, specifies which
86108627
individual thread within a thread group is executing in. This attribute is
@@ -8615,7 +8632,7 @@ The full documentation is available here: https://docs.microsoft.com/en-us/windo
86158632
}
86168633

86178634
def HLSLSV_GroupIDDocs : Documentation {
8618-
let Category = DocCatFunction;
8635+
let Category = DocHLSLSemantics;
86198636
let Content = [{
86208637
The ``SV_GroupID`` semantic, when applied to an input parameter, specifies which
86218638
thread group a shader is executing in. This attribute is only supported in compute shaders.
@@ -8625,7 +8642,7 @@ The full documentation is available here: https://docs.microsoft.com/en-us/windo
86258642
}
86268643

86278644
def HLSLSV_GroupIndexDocs : Documentation {
8628-
let Category = DocCatFunction;
8645+
let Category = DocHLSLSemantics;
86298646
let Content = [{
86308647
The ``SV_GroupIndex`` semantic, when applied to an input parameter, specifies a
86318648
data binding to map the group index to the specified parameter. This attribute
@@ -8682,7 +8699,7 @@ The full documentation is available here: https://learn.microsoft.com/en-us/wind
86828699
}
86838700

86848701
def HLSLSV_DispatchThreadIDDocs : Documentation {
8685-
let Category = DocCatFunction;
8702+
let Category = DocHLSLSemantics;
86868703
let Content = [{
86878704
The ``SV_DispatchThreadID`` semantic, when applied to an input parameter,
86888705
specifies a data binding to map the global thread offset within the Dispatch
@@ -8697,7 +8714,7 @@ The full documentation is available here: https://docs.microsoft.com/en-us/windo
86978714
}
86988715

86998716
def HLSLSV_PositionDocs : Documentation {
8700-
let Category = DocCatFunction;
8717+
let Category = DocHLSLSemantics;
87018718
let Content = [{
87028719
The ``SV_Position`` semantic, when applied to an input parameter in a pixel
87038720
shader, contains the location of the pixel center (x, y) in screen space.

clang/lib/AST/ByteCode/EvalEmitter.cpp

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -331,18 +331,17 @@ bool EvalEmitter::emitDestroy(uint32_t I, const SourceInfo &Info) {
331331
/// This is what we do here.
332332
void EvalEmitter::updateGlobalTemporaries() {
333333
for (const auto &[E, Temp] : S.SeenGlobalTemporaries) {
334-
if (UnsignedOrNone GlobalIndex = P.getGlobal(E)) {
335-
const Pointer &Ptr = P.getPtrGlobal(*GlobalIndex);
336-
APValue *Cached = Temp->getOrCreateValue(true);
337-
338-
if (OptPrimType T = Ctx.classify(E->getType())) {
339-
TYPE_SWITCH(
340-
*T, { *Cached = Ptr.deref<T>().toAPValue(Ctx.getASTContext()); });
341-
} else {
342-
if (std::optional<APValue> APV =
343-
Ptr.toRValue(Ctx, Temp->getTemporaryExpr()->getType()))
344-
*Cached = *APV;
345-
}
334+
UnsignedOrNone GlobalIndex = P.getGlobal(E);
335+
assert(GlobalIndex);
336+
const Pointer &Ptr = P.getPtrGlobal(*GlobalIndex);
337+
APValue *Cached = Temp->getOrCreateValue(true);
338+
if (OptPrimType T = Ctx.classify(E->getType())) {
339+
TYPE_SWITCH(*T,
340+
{ *Cached = Ptr.deref<T>().toAPValue(Ctx.getASTContext()); });
341+
} else {
342+
if (std::optional<APValue> APV =
343+
Ptr.toRValue(Ctx, Temp->getTemporaryExpr()->getType()))
344+
*Cached = *APV;
346345
}
347346
}
348347
S.SeenGlobalTemporaries.clear();

clang/lib/AST/ByteCode/Interp.h

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1527,15 +1527,12 @@ bool InitGlobal(InterpState &S, CodePtr OpPC, uint32_t I) {
15271527
template <PrimType Name, class T = typename PrimConv<Name>::T>
15281528
bool InitGlobalTemp(InterpState &S, CodePtr OpPC, uint32_t I,
15291529
const LifetimeExtendedTemporaryDecl *Temp) {
1530-
const Pointer &Ptr = S.P.getGlobal(I);
1531-
1532-
const T Value = S.Stk.peek<T>();
1533-
APValue APV = Value.toAPValue(S.getASTContext());
1534-
APValue *Cached = Temp->getOrCreateValue(true);
1535-
*Cached = APV;
1530+
if (S.EvalMode == EvaluationMode::ConstantFold)
1531+
return false;
1532+
assert(Temp);
15361533

1534+
const Pointer &Ptr = S.P.getGlobal(I);
15371535
assert(Ptr.getDeclDesc()->asExpr());
1538-
15391536
S.SeenGlobalTemporaries.push_back(
15401537
std::make_pair(Ptr.getDeclDesc()->asExpr(), Temp));
15411538

@@ -1549,20 +1546,14 @@ bool InitGlobalTemp(InterpState &S, CodePtr OpPC, uint32_t I,
15491546
/// 3) Initialized global with index \I with that
15501547
inline bool InitGlobalTempComp(InterpState &S, CodePtr OpPC,
15511548
const LifetimeExtendedTemporaryDecl *Temp) {
1549+
if (S.EvalMode == EvaluationMode::ConstantFold)
1550+
return false;
15521551
assert(Temp);
1553-
const Pointer &P = S.Stk.peek<Pointer>();
1554-
APValue *Cached = Temp->getOrCreateValue(true);
15551552

1553+
const Pointer &Ptr = S.Stk.peek<Pointer>();
15561554
S.SeenGlobalTemporaries.push_back(
1557-
std::make_pair(P.getDeclDesc()->asExpr(), Temp));
1558-
1559-
if (std::optional<APValue> APV =
1560-
P.toRValue(S.getASTContext(), Temp->getTemporaryExpr()->getType())) {
1561-
*Cached = *APV;
1562-
return true;
1563-
}
1564-
1565-
return false;
1555+
std::make_pair(Ptr.getDeclDesc()->asExpr(), Temp));
1556+
return true;
15661557
}
15671558

15681559
template <PrimType Name, class T = typename PrimConv<Name>::T>

clang/lib/AST/ByteCode/InterpState.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ InterpState::InterpState(State &Parent, Program &P, InterpStack &Stk,
2525
CheckingPotentialConstantExpression =
2626
Parent.CheckingPotentialConstantExpression;
2727
CheckingForUndefinedBehavior = Parent.CheckingForUndefinedBehavior;
28+
EvalMode = Parent.EvalMode;
2829
}
2930

3031
InterpState::InterpState(State &Parent, Program &P, InterpStack &Stk,
@@ -36,6 +37,7 @@ InterpState::InterpState(State &Parent, Program &P, InterpStack &Stk,
3637
CheckingPotentialConstantExpression =
3738
Parent.CheckingPotentialConstantExpression;
3839
CheckingForUndefinedBehavior = Parent.CheckingForUndefinedBehavior;
40+
EvalMode = Parent.EvalMode;
3941
}
4042

4143
bool InterpState::inConstantContext() const {

clang/lib/AST/ByteCode/State.h

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,27 @@ enum CheckSubobjectKind {
5050
CSK_VectorElement
5151
};
5252

53+
enum class EvaluationMode {
54+
/// Evaluate as a constant expression. Stop if we find that the expression
55+
/// is not a constant expression.
56+
ConstantExpression,
57+
58+
/// Evaluate as a constant expression. Stop if we find that the expression
59+
/// is not a constant expression. Some expressions can be retried in the
60+
/// optimizer if we don't constant fold them here, but in an unevaluated
61+
/// context we try to fold them immediately since the optimizer never
62+
/// gets a chance to look at it.
63+
ConstantExpressionUnevaluated,
64+
65+
/// Fold the expression to a constant. Stop if we hit a side-effect that
66+
/// we can't model.
67+
ConstantFold,
68+
69+
/// Evaluate in any way we know how. Don't worry about side-effects that
70+
/// can't be modeled.
71+
IgnoreSideEffects,
72+
};
73+
5374
namespace interp {
5475
class Frame;
5576
class SourceInfo;
@@ -149,6 +170,8 @@ class State {
149170
/// is set; this is used when evaluating ICEs in C.
150171
bool CheckingForUndefinedBehavior = false;
151172

173+
EvaluationMode EvalMode;
174+
152175
private:
153176
void addCallStack(unsigned Limit);
154177

0 commit comments

Comments
 (0)