Skip to content

Commit 2a16854

Browse files
SC llvm teamSC llvm team
authored andcommitted
Merged main:9fe6f6a0d430 into origin/amd-gfx:3be6366ceae6
Local branch origin/amd-gfx 3be6366 Merged main:0fc7aec34939 into origin/amd-gfx:bc9dded03b0b Remote branch main 9fe6f6a [bazel] Change `gentbl_cc_library(tbl_outs)` to dicts (llvm#134349)
2 parents 3be6366 + 9fe6f6a commit 2a16854

File tree

46 files changed

+2373
-4932
lines changed

Some content is hidden

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

46 files changed

+2373
-4932
lines changed

bolt/include/bolt/Passes/DataflowAnalysis.h

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -292,14 +292,17 @@ class DataflowAnalysis {
292292
/// Relies on a ptr map to fetch the previous instruction and then retrieve
293293
/// state. WARNING: Watch out for invalidated pointers. Do not use this
294294
/// function if you invalidated pointers after the analysis has been completed
295-
ErrorOr<const StateTy &> getStateBefore(const MCInst &Point) {
296-
return getStateAt(PrevPoint[&Point]);
295+
ErrorOr<const StateTy &> getStateBefore(const MCInst &Point) const {
296+
auto It = PrevPoint.find(&Point);
297+
if (It == PrevPoint.end())
298+
return make_error_code(std::errc::result_out_of_range);
299+
return getStateAt(It->getSecond());
297300
}
298301

299-
ErrorOr<const StateTy &> getStateBefore(ProgramPoint Point) {
302+
ErrorOr<const StateTy &> getStateBefore(ProgramPoint Point) const {
300303
if (Point.isBB())
301304
return getStateAt(*Point.getBB());
302-
return getStateAt(PrevPoint[Point.getInst()]);
305+
return getStateBefore(*Point.getInst());
303306
}
304307

305308
/// Remove any state annotations left by this analysis

bolt/lib/Passes/PAuthGadgetScanner.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -443,7 +443,7 @@ class PacRetAnalysis
443443
public:
444444
std::vector<MCInstReference>
445445
getLastClobberingInsts(const MCInst &Inst, BinaryFunction &BF,
446-
const ArrayRef<MCPhysReg> UsedDirtyRegs) {
446+
const ArrayRef<MCPhysReg> UsedDirtyRegs) const {
447447
if (RegsToTrackInstsFor.empty())
448448
return {};
449449
auto MaybeState = getStateBefore(Inst);

clang/docs/ReleaseNotes.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,9 @@ Improvements to Clang's diagnostics
319319
- ``-Wc++98-compat`` no longer diagnoses use of ``__auto_type`` or
320320
``decltype(auto)`` as though it was the extension for ``auto``. (#GH47900)
321321

322+
- Now correctly diagnose a tentative definition of an array with static
323+
storage duration in pedantic mode in C. (#GH50661)
324+
322325
Improvements to Clang's time-trace
323326
----------------------------------
324327

clang/include/clang/Basic/DiagnosticSemaKinds.td

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7350,8 +7350,9 @@ def err_typecheck_pointer_arith_void_type : Error<
73507350
"arithmetic on%select{ a|}0 pointer%select{|s}0 to void">;
73517351
def err_typecheck_decl_incomplete_type : Error<
73527352
"variable has incomplete type %0">;
7353-
def ext_typecheck_decl_incomplete_type : ExtWarn<
7354-
"tentative definition of variable with internal linkage has incomplete non-array type %0">,
7353+
def ext_typecheck_decl_incomplete_type : Extension<
7354+
"tentative definition of variable with internal linkage has incomplete "
7355+
"%select{non-array|array}0 type %1">,
73557356
InGroup<DiagGroup<"tentative-definition-incomplete-type">>;
73567357
def err_tentative_def_incomplete_type : Error<
73577358
"tentative definition has type %0 that is never completed">;

clang/lib/Sema/SemaDecl.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14246,7 +14246,8 @@ void Sema::ActOnUninitializedDecl(Decl *RealDecl) {
1424614246
Var->getLocation(), ArrayT->getElementType(),
1424714247
diag::err_array_incomplete_or_sizeless_type))
1424814248
Var->setInvalidDecl();
14249-
} else if (Var->getStorageClass() == SC_Static) {
14249+
}
14250+
if (Var->getStorageClass() == SC_Static) {
1425014251
// C99 6.9.2p3: If the declaration of an identifier for an object is
1425114252
// a tentative definition and has internal linkage (C99 6.2.2p3), the
1425214253
// declared type shall not be an incomplete type.
@@ -14258,7 +14259,8 @@ void Sema::ActOnUninitializedDecl(Decl *RealDecl) {
1425814259
// NOTE: to avoid multiple warnings, only check the first declaration.
1425914260
if (Var->isFirstDecl())
1426014261
RequireCompleteType(Var->getLocation(), Type,
14261-
diag::ext_typecheck_decl_incomplete_type);
14262+
diag::ext_typecheck_decl_incomplete_type,
14263+
Type->isArrayType());
1426214264
}
1426314265
}
1426414266

clang/test/C/drs/dr0xx.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,9 @@ int dr010_c = sizeof(dr010_t); /* expected-error {{invalid application of 'sizeo
139139
* Note: DR034 has a question resolved by DR011 and another question where the
140140
* result is UB.
141141
*/
142-
static int dr011_a[]; /* expected-warning {{tentative array definition assumed to have one element}} */
142+
static int dr011_a[]; /* expected-warning {{tentative array definition assumed to have one element}}
143+
expected-warning {{tentative definition of variable with internal linkage has incomplete array type 'int[]'}}
144+
*/
143145
void dr011(void) {
144146
extern int i[];
145147
{

clang/test/Sema/incomplete-decl.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,15 @@
33

44

55

6-
struct foo; // c-note 5 {{forward declaration of 'struct foo'}} \
6+
struct foo; // c-note 4 {{forward declaration of 'struct foo'}} \
77
cxx-note 3 {{forward declaration of 'foo'}}
88

99
void b; // expected-error {{variable has incomplete type 'void'}}
1010
struct foo f; // c-error {{tentative definition has type 'struct foo' that is never completed}} \
1111
cxx-error {{variable has incomplete type 'struct foo'}}
1212

1313
static void c; // expected-error {{variable has incomplete type 'void'}}
14-
static struct foo g; // c-warning {{tentative definition of variable with internal linkage has incomplete non-array type 'struct foo'}} \
15-
c-error {{tentative definition has type 'struct foo' that is never completed}} \
14+
static struct foo g; // c-error {{tentative definition has type 'struct foo' that is never completed}} \
1615
cxx-error {{variable has incomplete type 'struct foo'}}
1716

1817
extern void d; // cxx-error {{variable has incomplete type 'void'}}

clang/test/Sema/tentative-decls.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: %clang_cc1 %s -fsyntax-only -Wprivate-extern -verify
1+
// RUN: %clang_cc1 %s -fsyntax-only -Wprivate-extern -pedantic -verify
22

33
// PR3310
44
struct a x1; // expected-note 2{{forward declaration of 'struct a'}}
@@ -58,7 +58,7 @@ void func2(void)
5858
extern double *p;
5959
}
6060

61-
static int a0[];
61+
static int a0[]; // expected-warning {{tentative definition of variable with internal linkage has incomplete array type 'int[]'}}
6262
static int b0;
6363

6464
static int a0[] = { 4 };

flang/test/Transforms/DoConcurrent/loop_nest_test.f90

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
! REQUIRES: asserts
44

55
! RUN: %flang_fc1 -emit-hlfir -fopenmp -fdo-concurrent-to-openmp=host \
6-
! RUN: -mmlir -debug %s -o - 2> %t.log || true
6+
! RUN: -mmlir -debug -mmlir -mlir-disable-threading %s -o - 2> %t.log || true
77

88
! RUN: FileCheck %s < %t.log
99

lld/ELF/Arch/LoongArch.cpp

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ class LoongArch final : public TargetInfo {
3939
void relocate(uint8_t *loc, const Relocation &rel,
4040
uint64_t val) const override;
4141
bool relaxOnce(int pass) const override;
42+
void relocateAlloc(InputSectionBase &sec, uint8_t *buf) const override;
4243
void finalizeRelax(int passes) const override;
4344
};
4445
} // end anonymous namespace
@@ -53,6 +54,8 @@ enum Op {
5354
ADDI_W = 0x02800000,
5455
ADDI_D = 0x02c00000,
5556
ANDI = 0x03400000,
57+
ORI = 0x03800000,
58+
LU12I_W = 0x14000000,
5659
PCADDI = 0x18000000,
5760
PCADDU12I = 0x1c000000,
5861
LD_W = 0x28800000,
@@ -1002,6 +1005,88 @@ static bool relax(Ctx &ctx, InputSection &sec) {
10021005
return changed;
10031006
}
10041007

1008+
// Convert TLS IE to LE in the normal or medium code model.
1009+
// Original code sequence:
1010+
// * pcalau12i $a0, %ie_pc_hi20(sym)
1011+
// * ld.d $a0, $a0, %ie_pc_lo12(sym)
1012+
//
1013+
// The code sequence converted is as follows:
1014+
// * lu12i.w $a0, %le_hi20(sym) # le_hi20 != 0, otherwise NOP
1015+
// * ori $a0, src, %le_lo12(sym) # le_hi20 != 0, src = $a0,
1016+
// # otherwise, src = $zero
1017+
//
1018+
// When relaxation enables, redundant NOPs can be removed.
1019+
static void tlsIeToLe(uint8_t *loc, const Relocation &rel, uint64_t val) {
1020+
assert(isInt<32>(val) &&
1021+
"val exceeds the range of medium code model in tlsIeToLe");
1022+
1023+
bool isUInt12 = isUInt<12>(val);
1024+
const uint32_t currInsn = read32le(loc);
1025+
switch (rel.type) {
1026+
case R_LARCH_TLS_IE_PC_HI20:
1027+
if (isUInt12)
1028+
write32le(loc, insn(ANDI, R_ZERO, R_ZERO, 0)); // nop
1029+
else
1030+
write32le(loc, insn(LU12I_W, getD5(currInsn), extractBits(val, 31, 12),
1031+
0)); // lu12i.w $a0, %le_hi20
1032+
break;
1033+
case R_LARCH_TLS_IE_PC_LO12:
1034+
if (isUInt12)
1035+
write32le(loc, insn(ORI, getD5(currInsn), R_ZERO,
1036+
val)); // ori $a0, $zero, %le_lo12
1037+
else
1038+
write32le(loc, insn(ORI, getD5(currInsn), getJ5(currInsn),
1039+
lo12(val))); // ori $a0, $a0, %le_lo12
1040+
break;
1041+
}
1042+
}
1043+
1044+
void LoongArch::relocateAlloc(InputSectionBase &sec, uint8_t *buf) const {
1045+
const unsigned bits = ctx.arg.is64 ? 64 : 32;
1046+
uint64_t secAddr = sec.getOutputSection()->addr;
1047+
if (auto *s = dyn_cast<InputSection>(&sec))
1048+
secAddr += s->outSecOff;
1049+
else if (auto *ehIn = dyn_cast<EhInputSection>(&sec))
1050+
secAddr += ehIn->getParent()->outSecOff;
1051+
bool isExtreme = false;
1052+
const MutableArrayRef<Relocation> relocs = sec.relocs();
1053+
for (size_t i = 0, size = relocs.size(); i != size; ++i) {
1054+
Relocation &rel = relocs[i];
1055+
uint8_t *loc = buf + rel.offset;
1056+
uint64_t val = SignExtend64(
1057+
sec.getRelocTargetVA(ctx, rel, secAddr + rel.offset), bits);
1058+
1059+
switch (rel.expr) {
1060+
case R_RELAX_HINT:
1061+
continue;
1062+
case R_RELAX_TLS_IE_TO_LE:
1063+
if (rel.type == R_LARCH_TLS_IE_PC_HI20) {
1064+
// LoongArch does not support IE to LE optimization in the extreme code
1065+
// model. In this case, the relocs are as follows:
1066+
//
1067+
// * i -- R_LARCH_TLS_IE_PC_HI20
1068+
// * i+1 -- R_LARCH_TLS_IE_PC_LO12
1069+
// * i+2 -- R_LARCH_TLS_IE64_PC_LO20
1070+
// * i+3 -- R_LARCH_TLS_IE64_PC_HI12
1071+
isExtreme =
1072+
(i + 2 < size && relocs[i + 2].type == R_LARCH_TLS_IE64_PC_LO20);
1073+
}
1074+
if (isExtreme) {
1075+
rel.expr = getRelExpr(rel.type, *rel.sym, loc);
1076+
val = SignExtend64(sec.getRelocTargetVA(ctx, rel, secAddr + rel.offset),
1077+
bits);
1078+
relocateNoSym(loc, rel.type, val);
1079+
} else {
1080+
tlsIeToLe(loc, rel, val);
1081+
}
1082+
continue;
1083+
default:
1084+
break;
1085+
}
1086+
relocate(loc, rel, val);
1087+
}
1088+
}
1089+
10051090
// When relaxing just R_LARCH_ALIGN, relocDeltas is usually changed only once in
10061091
// the absence of a linker script. For call and load/store R_LARCH_RELAX, code
10071092
// shrinkage may reduce displacement and make more relocations eligible for

0 commit comments

Comments
 (0)