Skip to content

Commit

Permalink
Merge branch 'llvm:main' into llvmgh-101657
Browse files Browse the repository at this point in the history
  • Loading branch information
ravi-sh authored Jan 14, 2025
2 parents cab9674 + 06c6bae commit 054733b
Show file tree
Hide file tree
Showing 625 changed files with 26,942 additions and 16,109 deletions.
2 changes: 1 addition & 1 deletion .ci/metrics/metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"https://influx-prod-13-prod-us-east-0.grafana.net/api/v1/push/influx/write"
)
GITHUB_PROJECT = "llvm/llvm-project"
WORKFLOWS_TO_TRACK = ["Check code formatting", "LLVM Premerge Checks"]
WORKFLOWS_TO_TRACK = ["LLVM Premerge Checks"]
SCRAPE_INTERVAL_SECONDS = 5 * 60


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -513,7 +513,9 @@ void NarrowingConversionsCheck::handleFloatingCast(const ASTContext &Context,
return;
}
const BuiltinType *FromType = getBuiltinType(Rhs);
if (ToType->getKind() < FromType->getKind())
if (!llvm::APFloatBase::isRepresentableBy(
Context.getFloatTypeSemantics(FromType->desugar()),
Context.getFloatTypeSemantics(ToType->desugar())))
diagNarrowType(SourceLoc, Lhs, Rhs);
}
}
Expand Down
4 changes: 2 additions & 2 deletions clang-tools-extra/clang-tidy/modernize/UseAutoCheck.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ static void ignoreTypeLocClasses(
Loc = Loc.getNextTypeLoc();
}

static bool isMutliLevelPointerToTypeLocClasses(
static bool isMultiLevelPointerToTypeLocClasses(
TypeLoc Loc,
std::initializer_list<TypeLoc::TypeLocClass> const &LocClasses) {
ignoreTypeLocClasses(Loc, {TypeLoc::Paren, TypeLoc::Qualified});
Expand Down Expand Up @@ -424,7 +424,7 @@ void UseAutoCheck::replaceExpr(

auto Diag = diag(Range.getBegin(), Message);

bool ShouldReplenishVariableName = isMutliLevelPointerToTypeLocClasses(
bool ShouldReplenishVariableName = isMultiLevelPointerToTypeLocClasses(
TSI->getTypeLoc(), {TypeLoc::FunctionProto, TypeLoc::ConstantArray});

// Space after 'auto' to handle cases where the '*' in the pointer type is
Expand Down
9 changes: 7 additions & 2 deletions clang-tools-extra/docs/ReleaseNotes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,11 @@ Changes in existing checks
<clang-tidy/checks/bugprone/forwarding-reference-overload>` check by fixing
a crash when determining if an ``enable_if[_t]`` was found.

- Improve :doc:`bugprone-narrowing-conversions
<clang-tidy/checks/bugprone/narrowing-conversions>` to avoid incorrect check
results when floating point type is not ``float``, ``double`` and
``long double``.

- Improved :doc:`bugprone-optional-value-conversion
<clang-tidy/checks/bugprone/optional-value-conversion>` to support detecting
conversion directly by ``std::make_unique`` and ``std::make_shared``.
Expand Down Expand Up @@ -346,8 +351,8 @@ Changes in existing checks
<clang-tidy/checks/performance/move-const-arg>` check to fix a crash when
an argument type is declared but not defined.

- Improved :doc:`performance-unnecessary-copy-initialization`
<clang-tidy/checks/performance/unnecessary-copy-initialization> check
- Improved :doc:`performance-unnecessary-copy-initialization
<clang-tidy/checks/performance/unnecessary-copy-initialization>` check
to consider static member functions the same way as free functions.

- Improved :doc:`readability-container-contains
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,15 @@ void narrow_double_to_float_not_ok(double d) {
f = narrow_double_to_float_return();
}

float narrow_float16_to_float_return(_Float16 f) {
return f;
}

_Float16 narrow_float_to_float16_return(float f) {
return f;
// CHECK-MESSAGES: :[[@LINE-1]]:10: warning: narrowing conversion from 'float' to '_Float16' [bugprone-narrowing-conversions]
}

void narrow_fp_constants() {
float f;
f = 0.5; // [dcl.init.list] 7.2 : in-range fp constant to narrower float is not a narrowing.
Expand Down
12 changes: 12 additions & 0 deletions clang/docs/ReleaseNotes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1068,11 +1068,23 @@ X86 Support
Arm and AArch64 Support
^^^^^^^^^^^^^^^^^^^^^^^

- Implementation of SVE2.1 and SME2.1 in accordance with the Arm C Language
Extensions (ACLE) is now available.

- In the ARM Target, the frame pointer (FP) of a leaf function can be retained
by using the ``-fno-omit-frame-pointer`` option. If you want to eliminate the FP
in leaf functions after enabling ``-fno-omit-frame-pointer``, you can do so by adding
the ``-momit-leaf-frame-pointer`` option.

- SME keyword attributes which apply to function types are now represented in the
mangling of the type. This means that ``void foo(void (*f)() __arm_streaming);``
now has a different mangling from ``void foo(void (*f)());``.

- The ``__arm_agnostic`` keyword attribute was added to let users describe
a function that preserves SME state enabled by PSTATE.ZA without having to share
this state with its callers and without making the assumption that this state
exists.

- Support has been added for the following processors (-mcpu identifiers in parenthesis):

For AArch64:
Expand Down
4 changes: 2 additions & 2 deletions clang/include/clang/AST/DeclBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -1334,7 +1334,7 @@ class DeclListNode {

reference operator*() const {
assert(Ptr && "dereferencing end() iterator");
if (DeclListNode *CurNode = Ptr.dyn_cast<DeclListNode*>())
if (DeclListNode *CurNode = dyn_cast<DeclListNode *>(Ptr))
return CurNode->D;
return cast<NamedDecl *>(Ptr);
}
Expand All @@ -1344,7 +1344,7 @@ class DeclListNode {
inline iterator &operator++() { // ++It
assert(!Ptr.isNull() && "Advancing empty iterator");

if (DeclListNode *CurNode = Ptr.dyn_cast<DeclListNode*>())
if (DeclListNode *CurNode = dyn_cast<DeclListNode *>(Ptr))
Ptr = CurNode->Rest;
else
Ptr = nullptr;
Expand Down
8 changes: 5 additions & 3 deletions clang/include/clang/Basic/Builtins.td
Original file line number Diff line number Diff line change
Expand Up @@ -3347,10 +3347,12 @@ def VFork : LibBuiltin<"unistd.h"> {
}

// POSIX pthread.h
// FIXME: This should be a GNULibBuiltin, but it's currently missing the prototype.

def PthreadCreate : CustomEntry {
let Entry = "LIBBUILTIN(pthread_create, \"\", \"fC<2,3>\", PTHREAD_H, ALL_GNU_LANGUAGES)";
def PthreadCreate : GNULibBuiltin<"pthread.h"> {
let Spellings = ["pthread_create"];
let Attributes = [FunctionWithoutBuiltinPrefix, Callback<[2, 3]>];
// Note that we don't have an expressable prototype so we leave it empty.
let Prototype = "";
}

def SigSetJmp : LibBuiltin<"setjmp.h"> {
Expand Down
13 changes: 9 additions & 4 deletions clang/include/clang/Basic/BuiltinsBase.td
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ class IndexedAttribute<string baseMangling, int I> : Attribute<baseMangling> {
int Index = I;
}

class MultiIndexAttribute<string baseMangling, list<int> Is>
: Attribute<baseMangling> {
list<int> Indices = Is;
}

// Standard Attributes
// -------------------
def NoReturn : Attribute<"r">;
Expand Down Expand Up @@ -77,6 +82,10 @@ def Constexpr : Attribute<"E">;
// Builtin is immediate and must be constant evaluated. Implies Constexpr, and will only be supported in C++20 mode.
def Consteval : Attribute<"EG">;

// Callback behavior: the first index argument is called with the arguments
// indicated by the remaining indices.
class Callback<list<int> ArgIndices> : MultiIndexAttribute<"C", ArgIndices>;

// Builtin kinds
// =============

Expand All @@ -92,10 +101,6 @@ class Builtin {
bit EnableOpenCLLong = 0;
}

class CustomEntry {
string Entry;
}

class AtomicBuiltin : Builtin;

class LibBuiltin<string header, string languages = "ALL_LANGUAGES"> : Builtin {
Expand Down
4 changes: 2 additions & 2 deletions clang/include/clang/Driver/Options.td
Original file line number Diff line number Diff line change
Expand Up @@ -4108,7 +4108,7 @@ defm ms_tls_guards : BoolFOption<"ms-tls-guards",
"Do not emit code to perform on-demand initialization of thread-local variables">,
PosFlag<SetTrue>>;
def ftime_report : Flag<["-"], "ftime-report">, Group<f_Group>,
Visibility<[ClangOption, CC1Option]>,
Visibility<[ClangOption, CC1Option, FlangOption, FC1Option]>,
MarshallingInfoFlag<CodeGenOpts<"TimePasses">>;
def ftime_report_EQ: Joined<["-"], "ftime-report=">, Group<f_Group>,
Visibility<[ClangOption, CC1Option]>, Values<"per-pass,per-pass-run">,
Expand Down Expand Up @@ -4364,7 +4364,7 @@ defm split_machine_functions: BoolFOption<"split-machine-functions",
CodeGenOpts<"SplitMachineFunctions">, DefaultFalse,
PosFlag<SetTrue, [], [ClangOption, CC1Option], "Enable">,
NegFlag<SetFalse, [], [ClangOption], "Disable">,
BothFlags<[], [ClangOption], " late function splitting using profile information (x86 ELF)">>;
BothFlags<[], [ClangOption], " late function splitting using profile information (x86 and aarch64 ELF)">>;

defm strict_return : BoolFOption<"strict-return",
CodeGenOpts<"StrictReturn">, DefaultTrue,
Expand Down
47 changes: 44 additions & 3 deletions clang/lib/AST/ByteCode/Compiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,10 @@ bool InitLink::emit(Compiler<Emitter> *Ctx, const Expr *E) const {
if (!Ctx->emitConstUint32(Offset, E))
return false;
return Ctx->emitArrayElemPtrPopUint32(E);
case K_RVO:
return Ctx->emitRVOPtr(E);
case K_InitList:
return true;
default:
llvm_unreachable("Unhandled InitLink kind");
}
Expand Down Expand Up @@ -1717,6 +1721,8 @@ bool Compiler<Emitter>::VisitArraySubscriptExpr(const ArraySubscriptExpr *E) {
template <class Emitter>
bool Compiler<Emitter>::visitInitList(ArrayRef<const Expr *> Inits,
const Expr *ArrayFiller, const Expr *E) {
InitLinkScope<Emitter> ILS(this, InitLink::InitList());

QualType QT = E->getType();
if (const auto *AT = QT->getAs<AtomicType>())
QT = AT->getValueType();
Expand Down Expand Up @@ -1754,6 +1760,7 @@ bool Compiler<Emitter>::visitInitList(ArrayRef<const Expr *> Inits,
auto initPrimitiveField = [=](const Record::Field *FieldToInit,
const Expr *Init, PrimType T) -> bool {
InitStackScope<Emitter> ISS(this, isa<CXXDefaultInitExpr>(Init));
InitLinkScope<Emitter> ILS(this, InitLink::Field(FieldToInit->Offset));
if (!this->visit(Init))
return false;

Expand All @@ -1766,6 +1773,7 @@ bool Compiler<Emitter>::visitInitList(ArrayRef<const Expr *> Inits,
const Expr *Init) -> bool {
InitStackScope<Emitter> ISS(this, isa<CXXDefaultInitExpr>(Init));
InitLinkScope<Emitter> ILS(this, InitLink::Field(FieldToInit->Offset));

// Non-primitive case. Get a pointer to the field-to-initialize
// on the stack and recurse into visitInitializer().
if (!this->emitGetPtrField(FieldToInit->Offset, Init))
Expand Down Expand Up @@ -3812,6 +3820,7 @@ template <class Emitter> bool Compiler<Emitter>::visit(const Expr *E) {

if (!this->emitGetPtrLocal(*LocalIndex, E))
return false;
InitLinkScope<Emitter> ILS(this, InitLink::Temp(*LocalIndex));
return this->visitInitializer(E);
}

Expand Down Expand Up @@ -4848,18 +4857,49 @@ bool Compiler<Emitter>::VisitCXXThisExpr(const CXXThisExpr *E) {
// instance pointer of the current function frame, but e.g. to the declaration
// currently being initialized. Here we emit the necessary instruction(s) for
// this scenario.
if (!InitStackActive || !E->isImplicit())
if (!InitStackActive)
return this->emitThis(E);

if (InitStackActive && !InitStack.empty()) {
if (!InitStack.empty()) {
// If our init stack is, for example:
// 0 Stack: 3 (decl)
// 1 Stack: 6 (init list)
// 2 Stack: 1 (field)
// 3 Stack: 6 (init list)
// 4 Stack: 1 (field)
//
// We want to find the LAST element in it that's an init list,
// which is marked with the K_InitList marker. The index right
// before that points to an init list. We need to find the
// elements before the K_InitList element that point to a base
// (e.g. a decl or This), optionally followed by field, elem, etc.
// In the example above, we want to emit elements [0..2].
unsigned StartIndex = 0;
unsigned EndIndex = 0;
// Find the init list.
for (StartIndex = InitStack.size() - 1; StartIndex > 0; --StartIndex) {
if (InitStack[StartIndex].Kind == InitLink::K_InitList ||
InitStack[StartIndex].Kind == InitLink::K_This) {
EndIndex = StartIndex;
--StartIndex;
break;
}
}

// Walk backwards to find the base.
for (; StartIndex > 0; --StartIndex) {
if (InitStack[StartIndex].Kind == InitLink::K_InitList)
continue;

if (InitStack[StartIndex].Kind != InitLink::K_Field &&
InitStack[StartIndex].Kind != InitLink::K_Elem)
break;
}

for (unsigned I = StartIndex, N = InitStack.size(); I != N; ++I) {
// Emit the instructions.
for (unsigned I = StartIndex; I != EndIndex; ++I) {
if (InitStack[I].Kind == InitLink::K_InitList)
continue;
if (!InitStack[I].template emit<Emitter>(this, E))
return false;
}
Expand Down Expand Up @@ -4960,6 +5000,7 @@ bool Compiler<Emitter>::visitReturnStmt(const ReturnStmt *RS) {
if (!this->visit(RE))
return false;
} else {
InitLinkScope<Emitter> ILS(this, InitLink::RVO());
// RVO - construct the value in the return location.
if (!this->emitRVOPtr(RE))
return false;
Expand Down
4 changes: 4 additions & 0 deletions clang/lib/AST/ByteCode/Compiler.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,13 @@ struct InitLink {
K_Temp = 2,
K_Decl = 3,
K_Elem = 5,
K_RVO = 6,
K_InitList = 7
};

static InitLink This() { return InitLink{K_This}; }
static InitLink InitList() { return InitLink{K_InitList}; }
static InitLink RVO() { return InitLink{K_RVO}; }
static InitLink Field(unsigned Offset) {
InitLink IL{K_Field};
IL.Offset = Offset;
Expand Down
12 changes: 12 additions & 0 deletions clang/lib/AST/ByteCode/EvalEmitter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,18 @@ EvaluationResult EvalEmitter::interpretDecl(const VarDecl *VD,
if (!this->visitDeclAndReturn(VD, S.inConstantContext()))
EvalResult.setInvalid();

// Mark global variables as invalid if any diagnostic was produced.
if (S.hasPriorDiagnostic() && Context::shouldBeGloballyIndexed(VD)) {
if (auto GlobalIndex = P.getGlobal(VD)) {
Block *GlobalBlock = P.getGlobal(*GlobalIndex);
GlobalInlineDescriptor &GD =
*reinterpret_cast<GlobalInlineDescriptor *>(GlobalBlock->rawData());
GD.InitState = GlobalInitState::InitializerFailed;
if (GlobalBlock->isInitialized())
GlobalBlock->invokeDtor();
}
}

S.EvaluatingDecl = nullptr;
updateGlobalTemporaries();
return std::move(this->EvalResult);
Expand Down
2 changes: 1 addition & 1 deletion clang/lib/Analysis/ThreadSafetyCommon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ til::SExpr *SExprBuilder::translateDeclRefExpr(const DeclRefExpr *DRE,
: (cast<ObjCMethodDecl>(D)->getCanonicalDecl() == Canonical)) {
// Substitute call arguments for references to function parameters
if (const Expr *const *FunArgs =
Ctx->FunArgs.dyn_cast<const Expr *const *>()) {
dyn_cast<const Expr *const *>(Ctx->FunArgs)) {
assert(I < Ctx->NumArgs);
return translate(FunArgs[I], Ctx->Prev);
}
Expand Down
7 changes: 5 additions & 2 deletions clang/lib/Analysis/UnsafeBufferUsage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -453,8 +453,11 @@ AST_MATCHER(ArraySubscriptExpr, isSafeArraySubscript) {
return false;
}

if (const auto *IdxLit = dyn_cast<IntegerLiteral>(Node.getIdx())) {
const APInt ArrIdx = IdxLit->getValue();
Expr::EvalResult EVResult;
if (Node.getIdx()->EvaluateAsInt(EVResult, Finder->getASTContext())) {
llvm::APSInt ArrIdx = EVResult.Val.getInt();
// FIXME: ArrIdx.isNegative() we could immediately emit an error as that's a
// bug
if (ArrIdx.isNonNegative() && ArrIdx.getLimitedValue() < limit)
return true;
}
Expand Down
2 changes: 1 addition & 1 deletion clang/lib/Basic/SourceManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1222,7 +1222,7 @@ unsigned SourceManager::getPresumedColumnNumber(SourceLocation Loc,
return PLoc.getColumn();
}

// Check if mutli-byte word x has bytes between m and n, included. This may also
// Check if multi-byte word x has bytes between m and n, included. This may also
// catch bytes equal to n + 1.
// The returned value holds a 0x80 at each byte position that holds a match.
// see http://graphics.stanford.edu/~seander/bithacks.html#HasBetweenInWord
Expand Down
2 changes: 1 addition & 1 deletion clang/lib/CodeGen/CGCall.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4507,7 +4507,7 @@ void CodeGenFunction::EmitCallArgs(
// First, if a prototype was provided, use those argument types.
bool IsVariadic = false;
if (Prototype.P) {
const auto *MD = Prototype.P.dyn_cast<const ObjCMethodDecl *>();
const auto *MD = dyn_cast<const ObjCMethodDecl *>(Prototype.P);
if (MD) {
IsVariadic = MD->isVariadic();
ExplicitCC = getCallingConventionForDecl(
Expand Down
13 changes: 8 additions & 5 deletions clang/lib/CodeGen/CGOpenMPRuntime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5880,10 +5880,13 @@ void CGOpenMPRuntime::emitUsesAllocatorsFini(CodeGenFunction &CGF,

void CGOpenMPRuntime::computeMinAndMaxThreadsAndTeams(
const OMPExecutableDirective &D, CodeGenFunction &CGF,
int32_t &MinThreadsVal, int32_t &MaxThreadsVal, int32_t &MinTeamsVal,
int32_t &MaxTeamsVal) {
llvm::OpenMPIRBuilder::TargetKernelDefaultAttrs &Attrs) {
assert(Attrs.MaxTeams.size() == 1 && Attrs.MaxThreads.size() == 1 &&
"invalid default attrs structure");
int32_t &MaxTeamsVal = Attrs.MaxTeams.front();
int32_t &MaxThreadsVal = Attrs.MaxThreads.front();

getNumTeamsExprForTargetDirective(CGF, D, MinTeamsVal, MaxTeamsVal);
getNumTeamsExprForTargetDirective(CGF, D, Attrs.MinTeams, MaxTeamsVal);
getNumThreadsExprForTargetDirective(CGF, D, MaxThreadsVal,
/*UpperBoundOnly=*/true);

Expand All @@ -5901,12 +5904,12 @@ void CGOpenMPRuntime::computeMinAndMaxThreadsAndTeams(
else
continue;

MinThreadsVal = std::max(MinThreadsVal, AttrMinThreadsVal);
Attrs.MinThreads = std::max(Attrs.MinThreads, AttrMinThreadsVal);
if (AttrMaxThreadsVal > 0)
MaxThreadsVal = MaxThreadsVal > 0
? std::min(MaxThreadsVal, AttrMaxThreadsVal)
: AttrMaxThreadsVal;
MinTeamsVal = std::max(MinTeamsVal, AttrMinBlocksVal);
Attrs.MinTeams = std::max(Attrs.MinTeams, AttrMinBlocksVal);
if (AttrMaxBlocksVal > 0)
MaxTeamsVal = MaxTeamsVal > 0 ? std::min(MaxTeamsVal, AttrMaxBlocksVal)
: AttrMaxBlocksVal;
Expand Down
Loading

0 comments on commit 054733b

Please sign in to comment.