Skip to content

Commit

Permalink
merge main into amd-staging
Browse files Browse the repository at this point in the history
Change-Id: Ide285ba3821b1e0173b2e760a8df6d53f19d375d
  • Loading branch information
ronlieb committed Sep 5, 2024
2 parents dcf5a00 + 3299bc8 commit 466b528
Show file tree
Hide file tree
Showing 63 changed files with 945 additions and 690 deletions.
12 changes: 10 additions & 2 deletions clang/cmake/caches/Release.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,22 @@ set(STAGE1_RUNTIMES "compiler-rt")

if (LLVM_RELEASE_ENABLE_PGO)
list(APPEND STAGE1_PROJECTS "lld")
set(CLANG_BOOTSTRAP_TARGETS
set(tmp_targets
generate-profdata
stage2-package
stage2-clang
stage2
stage2-install
stage2-check-all
stage2-check-llvm
stage2-check-clang CACHE STRING "")
stage2-check-clang)

foreach(X IN LISTS LLVM_RELEASE_FINAL_STAGE_TARGETS)
list(APPEND tmp_targets "stage2-${X}")
endforeach()
list(REMOVE_DUPLICATES tmp_targets)

set(CLANG_BOOTSTRAP_TARGETS "${tmp_targets}" CACHE STRING "")

# Configuration for stage2-instrumented
set(BOOTSTRAP_CLANG_ENABLE_BOOTSTRAP ON CACHE STRING "")
Expand Down
4 changes: 4 additions & 0 deletions clang/docs/ReleaseNotes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,8 @@ Improvements to Clang's diagnostics
- The lifetimebound and GSL analysis in clang are coherent, allowing clang to
detect more use-after-free bugs. (#GH100549).

- Clang now warns for u8 character literals used in C23 with ``-Wpre-c23-compat`` instead of ``-Wpre-c++17-compat``.

Improvements to Clang's time-trace
----------------------------------

Expand Down Expand Up @@ -360,6 +362,8 @@ Bug Fixes to C++ Support
- Fix an issue with dependent source location expressions (#GH106428), (#GH81155), (#GH80210), (#GH85373)
- Fixed a bug in the substitution of empty pack indexing types. (#GH105903)
- Clang no longer tries to capture non-odr used default arguments of template parameters of generic lambdas (#GH107048)
- Fixed a bug where defaulted comparison operators would remove ``const`` from base classes. (#GH102588)


Bug Fixes to AST Handling
^^^^^^^^^^^^^^^^^^^^^^^^^
Expand Down
3 changes: 3 additions & 0 deletions clang/include/clang/Basic/DiagnosticLexKinds.td
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,9 @@ def warn_cxx98_compat_unicode_literal : Warning<
def warn_cxx14_compat_u8_character_literal : Warning<
"unicode literals are incompatible with C++ standards before C++17">,
InGroup<CXXPre17Compat>, DefaultIgnore;
def warn_c17_compat_u8_character_literal : Warning<
"unicode literals are incompatible with C standards before C23">,
InGroup<CPre23Compat>, DefaultIgnore;
def warn_cxx11_compat_user_defined_literal : Warning<
"identifier after literal will be treated as a user-defined literal suffix "
"in C++11">, InGroup<CXX11Compat>, DefaultIgnore;
Expand Down
2 changes: 1 addition & 1 deletion clang/include/clang/Basic/SourceManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -724,7 +724,7 @@ class SourceManager : public RefCountedBase<SourceManager> {
///
/// Negative FileIDs are indexes into this table. To get from ID to an index,
/// use (-ID - 2).
llvm::PagedVector<SrcMgr::SLocEntry> LoadedSLocEntryTable;
llvm::PagedVector<SrcMgr::SLocEntry, 32> LoadedSLocEntryTable;

/// For each allocation in LoadedSLocEntryTable, we keep the first FileID.
/// We assume exactly one allocation per AST file, and use that to determine
Expand Down
13 changes: 13 additions & 0 deletions clang/lib/ExtractAPI/DeclarationFragments.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,19 @@ DeclarationFragments DeclarationFragmentsBuilder::getFragmentsForType(

DeclarationFragments Fragments;

if (const MacroQualifiedType *MQT = dyn_cast<MacroQualifiedType>(T)) {
Fragments.append(
getFragmentsForType(MQT->getUnderlyingType(), Context, After));
return Fragments;
}

if (const AttributedType *AT = dyn_cast<AttributedType>(T)) {
// FIXME: Serialize Attributes correctly
Fragments.append(
getFragmentsForType(AT->getModifiedType(), Context, After));
return Fragments;
}

// An ElaboratedType is a sugar for types that are referred to using an
// elaborated keyword, e.g., `struct S`, `enum E`, or (in C++) via a
// qualified name, e.g., `N::M::type`, or both.
Expand Down
4 changes: 3 additions & 1 deletion clang/lib/Lex/Lexer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2428,7 +2428,9 @@ bool Lexer::LexCharConstant(Token &Result, const char *CurPtr,
? diag::warn_cxx98_compat_unicode_literal
: diag::warn_c99_compat_unicode_literal);
else if (Kind == tok::utf8_char_constant)
Diag(BufferPtr, diag::warn_cxx14_compat_u8_character_literal);
Diag(BufferPtr, LangOpts.CPlusPlus
? diag::warn_cxx14_compat_u8_character_literal
: diag::warn_c17_compat_u8_character_literal);
}

char C = getAndAdvanceChar(CurPtr, Result);
Expand Down
10 changes: 6 additions & 4 deletions clang/lib/Sema/SemaDeclCXX.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8476,10 +8476,12 @@ class DefaultedComparisonSynthesizer
if (Obj.first.isInvalid() || Obj.second.isInvalid())
return {ExprError(), ExprError()};
CXXCastPath Path = {Base};
return {S.ImpCastExprToType(Obj.first.get(), Base->getType(),
CK_DerivedToBase, VK_LValue, &Path),
S.ImpCastExprToType(Obj.second.get(), Base->getType(),
CK_DerivedToBase, VK_LValue, &Path)};
const auto CastToBase = [&](Expr *E) {
QualType ToType = S.Context.getQualifiedType(
Base->getType(), E->getType().getQualifiers());
return S.ImpCastExprToType(E, ToType, CK_DerivedToBase, VK_LValue, &Path);
};
return {CastToBase(Obj.first.get()), CastToBase(Obj.second.get())};
}

ExprPair getField(FieldDecl *Field) {
Expand Down
24 changes: 24 additions & 0 deletions clang/test/ExtractAPI/attributed-typedef.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// RUN: rm -rf %t
// RUN: %clang_cc1 -extract-api --pretty-sgf --emit-sgf-symbol-labels-for-testing \
// RUN: -triple arm64-apple-macosx -x objective-c-header %s -o %t/output.symbols.json

_Pragma("clang assume_nonnull begin")

struct Foo { int a; };
typedef struct Foo *Bar;
// RUN: FileCheck %s -input-file %t/output.symbols.json --check-prefix FUNC
void func(Bar b);
// FUNC-LABEL: "!testLabel": "c:@F@func",
// CHECK-NOT: Foo
// CHECK: "pathComponents"

// RUN: FileCheck %s --input-file %t/output.symbols.json --check-prefix THING
#define SWIFT_NAME(_name) __attribute__((swift_name(#_name)))
extern Bar const thing SWIFT_NAME(swiftThing);
// THING-LABEL: "!testLabel": "c:@thing"
// THING-NOT: Foo
// THING: "pathComponents"

_Pragma("clang assume_nonnull end")

// expected-no-diagnostics
1 change: 1 addition & 0 deletions clang/test/Sema/pre-c2x-compat.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// RUN: %clang_cc1 %s -std=c2x -Wpre-c2x-compat -pedantic -fsyntax-only -verify

int digit_seps = 123'456; // expected-warning {{digit separators are incompatible with C standards before C23}}
unsigned char u8_char = u8'x'; // expected-warning {{unicode literals are incompatible with C standards before C23}}
50 changes: 50 additions & 0 deletions clang/test/SemaCXX/cxx20-default-compare.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
// RUN: %clang_cc1 %s -std=c++23 -verify -Wfloat-equal

#include "Inputs/std-compare.h"

struct Foo {
float val;
bool operator==(const Foo &) const;
Expand All @@ -15,3 +17,51 @@ bool operator==(const Foo &, const Foo &) = default; // expected-warning {{comp

// Declare the defaulted comparison function as a non-member function. Arguments are passed by value.
bool operator==(Foo, Foo) = default; // expected-warning {{comparing floating point with == or != is unsafe}} expected-note {{in defaulted equality comparison operator for 'Foo' first required here}}

namespace GH102588 {
struct A {
int i = 0;
constexpr operator int() const { return i; }
constexpr operator int&() { return ++i; }
};

struct B : A {
bool operator==(const B &) const = default;
};

constexpr bool f() {
B x;
return x == x;
}

static_assert(f());

struct ConstOnly {
std::strong_ordering operator<=>(const ConstOnly&) const;
std::strong_ordering operator<=>(ConstOnly&) = delete;
friend bool operator==(const ConstOnly&, const ConstOnly&);
friend bool operator==(ConstOnly&, ConstOnly&) = delete;
};

struct MutOnly {
std::strong_ordering operator<=>(const MutOnly&) const = delete;;
std::strong_ordering operator<=>(MutOnly&);
friend bool operator==(const MutOnly&, const MutOnly&) = delete;;
friend bool operator==(MutOnly&, MutOnly&);
};

struct ConstCheck : ConstOnly {
friend std::strong_ordering operator<=>(const ConstCheck&, const ConstCheck&) = default;
std::strong_ordering operator<=>(ConstCheck const& __restrict) const __restrict = default;
friend bool operator==(const ConstCheck&, const ConstCheck&) = default;
bool operator==(this const ConstCheck&, const ConstCheck&) = default;
};

// FIXME: Non-reference explicit object parameter are rejected
struct MutCheck : MutOnly {
friend bool operator==(MutCheck, MutCheck) = default;
// std::strong_ordering operator<=>(this MutCheck, MutCheck) = default;
friend std::strong_ordering operator<=>(MutCheck, MutCheck) = default;
// bool operator==(this MutCheck, MutCheck) = default;
};
}
2 changes: 1 addition & 1 deletion llvm/include/llvm/ADT/PagedVector.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ template <typename T, size_t PageSize = 1024 / sizeof(T)> class PagedVector {
assert(Index / PageSize < PageToDataPtrs.size());
T *&PagePtr = PageToDataPtrs[Index / PageSize];
// If the page was not yet allocated, allocate it.
if (!PagePtr) {
if (LLVM_UNLIKELY(!PagePtr)) {
PagePtr = Allocator.getPointer()->template Allocate<T>(PageSize);
// We need to invoke the default constructor on all the elements of the
// page.
Expand Down
2 changes: 1 addition & 1 deletion llvm/include/llvm/CodeGen/DebugHandlerBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ class DebugHandlerBase {

/// This location indicates end of function prologue and beginning of
/// function body.
DebugLoc PrologEndLoc;
const MachineInstr *PrologEndLoc;

/// This block includes epilogue instructions.
const MachineBasicBlock *EpilogBeginBlock = nullptr;
Expand Down
9 changes: 0 additions & 9 deletions llvm/include/llvm/CodeGen/TargetInstrInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -2278,15 +2278,6 @@ class TargetInstrInfo : public MCInstrInfo {
llvm_unreachable("unknown number of operands necessary");
}

/// Gets the opcode for the Pseudo Instruction used to initialize
/// the undef value. If no Instruction is available, this will
/// fail compilation.
virtual unsigned getUndefInitOpcode(unsigned RegClassID) const {
(void)RegClassID;

llvm_unreachable("Unexpected register class.");
}

private:
mutable std::unique_ptr<MIRFormatter> Formatter;
unsigned CallFrameSetupOpcode, CallFrameDestroyOpcode;
Expand Down
5 changes: 5 additions & 0 deletions llvm/include/llvm/Support/TargetOpcodes.def
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,11 @@ HANDLE_TARGET_OPCODE(INSERT_SUBREG)
/// IMPLICIT_DEF - This is the MachineInstr-level equivalent of undef.
HANDLE_TARGET_OPCODE(IMPLICIT_DEF)

/// Explicit undef initialization used past IMPLICIT_DEF elimination in cases
/// where an undef operand must be allocated to a different register than an
/// early-clobber result operand.
HANDLE_TARGET_OPCODE(INIT_UNDEF)

/// SUBREG_TO_REG - Assert the value of bits in a super register.
/// The result of this instruction is the value of the second operand inserted
/// into the subregister specified by the third operand. All other bits are
Expand Down
7 changes: 7 additions & 0 deletions llvm/include/llvm/Target/Target.td
Original file line number Diff line number Diff line change
Expand Up @@ -1254,6 +1254,13 @@ def IMPLICIT_DEF : StandardPseudoInstruction {
let isAsCheapAsAMove = true;
let isMeta = true;
}
def INIT_UNDEF : StandardPseudoInstruction {
let OutOperandList = (outs unknown:$dst);
let InOperandList = (ins);
let AsmString = "";
let hasSideEffects = false;
let Size = 0;
}
def SUBREG_TO_REG : StandardPseudoInstruction {
let OutOperandList = (outs unknown:$dst);
let InOperandList = (ins unknown:$implsrc, unknown:$subsrc, i32imm:$subidx);
Expand Down
4 changes: 4 additions & 0 deletions llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1879,6 +1879,10 @@ void AsmPrinter::emitFunctionBody() {
// This instruction is only used to note jump table debug info, it's
// purely meta information.
break;
case TargetOpcode::INIT_UNDEF:
// This is only used to influence register allocation behavior, no
// actual initialization is needed.
break;
default:
emitInstruction(&MI);
if (CanDoExtraAnalysis) {
Expand Down
28 changes: 14 additions & 14 deletions llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2268,9 +2268,9 @@ void DwarfDebug::beginInstruction(const MachineInstr *MI) {
// (The new location might be an explicit line 0, which we do emit.)
if (DL.getLine() == 0 && LastAsmLine == 0)
return;
if (DL == PrologEndLoc) {
if (MI == PrologEndLoc) {
Flags |= DWARF2_FLAG_PROLOGUE_END | DWARF2_FLAG_IS_STMT;
PrologEndLoc = DebugLoc();
PrologEndLoc = nullptr;
}
// If the line changed, we call that a new statement; unless we went to
// line 0 and came back, in which case it is not a new statement. We also
Expand All @@ -2288,10 +2288,11 @@ void DwarfDebug::beginInstruction(const MachineInstr *MI) {
PrevInstLoc = DL;
}

static std::pair<DebugLoc, bool> findPrologueEndLoc(const MachineFunction *MF) {
static std::pair<const MachineInstr *, bool>
findPrologueEndLoc(const MachineFunction *MF) {
// First known non-DBG_VALUE and non-frame setup location marks
// the beginning of the function body.
DebugLoc LineZeroLoc;
const MachineInstr *LineZeroLoc = nullptr;
const Function &F = MF->getFunction();

// Some instructions may be inserted into prologue after this function. Must
Expand All @@ -2308,9 +2309,9 @@ static std::pair<DebugLoc, bool> findPrologueEndLoc(const MachineFunction *MF) {
// meaningful breakpoint. If none is found, return the first
// location after the frame setup.
if (MI.getDebugLoc().getLine())
return std::make_pair(MI.getDebugLoc(), IsEmptyPrologue);
return std::make_pair(&MI, IsEmptyPrologue);

LineZeroLoc = MI.getDebugLoc();
LineZeroLoc = &MI;
}
IsEmptyPrologue = false;
}
Expand Down Expand Up @@ -2341,10 +2342,10 @@ static void recordSourceLine(AsmPrinter &Asm, unsigned Line, unsigned Col,
Discriminator, Fn);
}

DebugLoc DwarfDebug::emitInitialLocDirective(const MachineFunction &MF,
unsigned CUID) {
std::pair<DebugLoc, bool> PrologEnd = findPrologueEndLoc(&MF);
DebugLoc PrologEndLoc = PrologEnd.first;
const MachineInstr *
DwarfDebug::emitInitialLocDirective(const MachineFunction &MF, unsigned CUID) {
std::pair<const MachineInstr *, bool> PrologEnd = findPrologueEndLoc(&MF);
const MachineInstr *PrologEndLoc = PrologEnd.first;
bool IsEmptyPrologue = PrologEnd.second;

// Get beginning of function.
Expand All @@ -2355,16 +2356,15 @@ DebugLoc DwarfDebug::emitInitialLocDirective(const MachineFunction &MF,

// Ensure the compile unit is created if the function is called before
// beginFunction().
(void)getOrCreateDwarfCompileUnit(
MF.getFunction().getSubprogram()->getUnit());
DISubprogram *SP = MF.getFunction().getSubprogram();
(void)getOrCreateDwarfCompileUnit(SP->getUnit());
// We'd like to list the prologue as "not statements" but GDB behaves
// poorly if we do that. Revisit this with caution/GDB (7.5+) testing.
const DISubprogram *SP = PrologEndLoc->getInlinedAtScope()->getSubprogram();
::recordSourceLine(*Asm, SP->getScopeLine(), 0, SP, DWARF2_FLAG_IS_STMT,
CUID, getDwarfVersion(), getUnits());
return PrologEndLoc;
}
return DebugLoc();
return nullptr;
}

// Gather pre-function debug information. Assumes being called immediately
Expand Down
6 changes: 4 additions & 2 deletions llvm/lib/CodeGen/AsmPrinter/DwarfDebug.h
Original file line number Diff line number Diff line change
Expand Up @@ -757,8 +757,10 @@ class DwarfDebug : public DebugHandlerBase {
/// Emit all Dwarf sections that should come after the content.
void endModule() override;

/// Emits inital debug location directive.
DebugLoc emitInitialLocDirective(const MachineFunction &MF, unsigned CUID);
/// Emits inital debug location directive. Returns instruction at which
/// the function prologue ends.
const MachineInstr *emitInitialLocDirective(const MachineFunction &MF,
unsigned CUID);

/// Process beginning of an instruction.
void beginInstruction(const MachineInstr *MI) override;
Expand Down
7 changes: 3 additions & 4 deletions llvm/lib/CodeGen/InitUndef.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -177,8 +177,7 @@ bool InitUndef::handleSubReg(MachineFunction &MF, MachineInstr &MI,
Register TmpInitSubReg = MRI->createVirtualRegister(SubRegClass);
LLVM_DEBUG(dbgs() << "Register Class ID" << SubRegClass->getID() << "\n");
BuildMI(*MI.getParent(), &MI, MI.getDebugLoc(),
TII->get(TII->getUndefInitOpcode(SubRegClass->getID())),
TmpInitSubReg);
TII->get(TargetOpcode::INIT_UNDEF), TmpInitSubReg);
Register NewReg = MRI->createVirtualRegister(TargetRegClass);
BuildMI(*MI.getParent(), &MI, MI.getDebugLoc(),
TII->get(TargetOpcode::INSERT_SUBREG), NewReg)
Expand All @@ -203,9 +202,9 @@ bool InitUndef::fixupIllOperand(MachineInstr *MI, MachineOperand &MO) {
const TargetRegisterClass *TargetRegClass =
TRI->getLargestSuperClass(MRI->getRegClass(MO.getReg()));
LLVM_DEBUG(dbgs() << "Register Class ID" << TargetRegClass->getID() << "\n");
unsigned Opcode = TII->getUndefInitOpcode(TargetRegClass->getID());
Register NewReg = MRI->createVirtualRegister(TargetRegClass);
BuildMI(*MI->getParent(), MI, MI->getDebugLoc(), TII->get(Opcode), NewReg);
BuildMI(*MI->getParent(), MI, MI->getDebugLoc(),
TII->get(TargetOpcode::INIT_UNDEF), NewReg);
MO.setReg(NewReg);
if (MO.isUndef())
MO.setIsUndef(false);
Expand Down
Loading

0 comments on commit 466b528

Please sign in to comment.