Skip to content

Commit 5118390

Browse files
SC llvm teamSC llvm team
SC llvm team
authored and
SC llvm team
committed
Merged main:202dda8e5c3f into amd-gfx:6034dce6d758
Local branch amd-gfx 6034dce Merged main:a90e215dfbc9 into amd-gfx:57a10ab39b40 Remote branch main 202dda8 [BOLT][utils] Bump default time threshold to 1s in nfc-stat-parser
2 parents 6034dce + 202dda8 commit 5118390

39 files changed

+716
-560
lines changed
Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
#include <stdio.h>
2-
#include <stdlib.h>
3-
#include <unistd.h>
4-
51
int add(int a, int b) { return a + b; }
62
int minus(int a, int b) { return a - b; }
73
int multiple(int a, int b) { return a * b; }
@@ -15,12 +11,12 @@ int main() {
1511
int a = 16;
1612
int b = 8;
1713

18-
for (int i = 1; i < 100000; i++) {
14+
for (int i = 1; i < 1000000; i++) {
1915
add(a, b);
2016
minus(a, b);
2117
multiple(a, b);
2218
divide(a, b);
2319
}
2420

2521
return 0;
26-
}
22+
}

bolt/utils/nfc-stat-parser.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ def main():
1919
)
2020
parser.add_argument(
2121
"--check_longer_than",
22-
default=0.5,
22+
default=1,
2323
type=float,
2424
help="Only warn on tests longer than X seconds for at least one side",
2525
)

clang/include/clang/StaticAnalyzer/Core/PathSensitive/SValBuilder.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,15 @@ class SValBuilder {
215215
const LocationContext *LCtx,
216216
QualType type, unsigned Count);
217217

218+
/// Create an SVal representing the result of an alloca()-like call, that is,
219+
/// an AllocaRegion on the stack.
220+
///
221+
/// After calling this function, it's a good idea to set the extent of the
222+
/// returned AllocaRegion.
223+
loc::MemRegionVal getAllocaRegionVal(const Expr *E,
224+
const LocationContext *LCtx,
225+
unsigned Count);
226+
218227
DefinedOrUnknownSVal getDerivedRegionValueSymbolVal(
219228
SymbolRef parentSymbol, const TypedValueRegion *region);
220229

clang/lib/CodeGen/CGDebugInfo.cpp

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1680,14 +1680,26 @@ CGDebugInfo::CreateRecordStaticField(const VarDecl *Var, llvm::DIType *RecordTy,
16801680
unsigned LineNumber = getLineNumber(Var->getLocation());
16811681
StringRef VName = Var->getName();
16821682

1683+
// FIXME: to avoid complications with type merging we should
1684+
// emit the constant on the definition instead of the declaration.
1685+
llvm::Constant *C = nullptr;
1686+
if (Var->getInit()) {
1687+
const APValue *Value = Var->evaluateValue();
1688+
if (Value) {
1689+
if (Value->isInt())
1690+
C = llvm::ConstantInt::get(CGM.getLLVMContext(), Value->getInt());
1691+
if (Value->isFloat())
1692+
C = llvm::ConstantFP::get(CGM.getLLVMContext(), Value->getFloat());
1693+
}
1694+
}
1695+
16831696
llvm::DINode::DIFlags Flags = getAccessFlag(Var->getAccess(), RD);
16841697
auto Tag = CGM.getCodeGenOpts().DwarfVersion >= 5
16851698
? llvm::dwarf::DW_TAG_variable
16861699
: llvm::dwarf::DW_TAG_member;
16871700
auto Align = getDeclAlignIfRequired(Var, CGM.getContext());
1688-
llvm::DIDerivedType *GV =
1689-
DBuilder.createStaticMemberType(RecordTy, VName, VUnit, LineNumber, VTy,
1690-
Flags, /* Val */ nullptr, Tag, Align);
1701+
llvm::DIDerivedType *GV = DBuilder.createStaticMemberType(
1702+
RecordTy, VName, VUnit, LineNumber, VTy, Flags, C, Tag, Align);
16911703
StaticDataMemberCache[Var->getCanonicalDecl()].reset(GV);
16921704
StaticDataMemberDefinitionsToEmit.push_back(Var->getCanonicalDecl());
16931705
return GV;

clang/lib/StaticAnalyzer/Checkers/BuiltinFunctionChecker.cpp

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -81,22 +81,20 @@ bool BuiltinFunctionChecker::evalCall(const CallEvent &Call,
8181

8282
case Builtin::BI__builtin_alloca_with_align:
8383
case Builtin::BI__builtin_alloca: {
84-
// FIXME: Refactor into StoreManager itself?
85-
MemRegionManager& RM = C.getStoreManager().getRegionManager();
86-
const AllocaRegion* R =
87-
RM.getAllocaRegion(CE, C.blockCount(), C.getLocationContext());
88-
89-
// Set the extent of the region in bytes. This enables us to use the
90-
// SVal of the argument directly. If we save the extent in bits, we
91-
// cannot represent values like symbol*8.
92-
auto Size = Call.getArgSVal(0);
93-
if (Size.isUndef())
94-
return true; // Return true to model purity.
95-
96-
state = setDynamicExtent(state, R, Size.castAs<DefinedOrUnknownSVal>(),
97-
C.getSValBuilder());
84+
SValBuilder &SVB = C.getSValBuilder();
85+
const loc::MemRegionVal R =
86+
SVB.getAllocaRegionVal(CE, C.getLocationContext(), C.blockCount());
9887

99-
C.addTransition(state->BindExpr(CE, LCtx, loc::MemRegionVal(R)));
88+
// Set the extent of the region in bytes. This enables us to use the SVal
89+
// of the argument directly. If we saved the extent in bits, it'd be more
90+
// difficult to reason about values like symbol*8.
91+
auto Size = Call.getArgSVal(0);
92+
if (auto DefSize = Size.getAs<DefinedOrUnknownSVal>()) {
93+
// This `getAs()` is mostly paranoia, because core.CallAndMessage reports
94+
// undefined function arguments (unless it's disabled somehow).
95+
state = setDynamicExtent(state, R.getRegion(), *DefSize, SVB);
96+
}
97+
C.addTransition(state->BindExpr(CE, LCtx, R));
10098
return true;
10199
}
102100

clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1728,13 +1728,15 @@ ProgramStateRef MallocChecker::MallocMemAux(CheckerContext &C,
17281728
return nullptr;
17291729

17301730
// Bind the return value to the symbolic value from the heap region.
1731-
// TODO: We could rewrite post visit to eval call; 'malloc' does not have
1732-
// side effects other than what we model here.
1731+
// TODO: move use of this functions to an EvalCall callback, becasue
1732+
// BindExpr() should'nt be used elsewhere.
17331733
unsigned Count = C.blockCount();
1734-
SValBuilder &svalBuilder = C.getSValBuilder();
1734+
SValBuilder &SVB = C.getSValBuilder();
17351735
const LocationContext *LCtx = C.getPredecessor()->getLocationContext();
1736-
DefinedSVal RetVal = svalBuilder.getConjuredHeapSymbolVal(CE, LCtx, Count)
1737-
.castAs<DefinedSVal>();
1736+
DefinedSVal RetVal =
1737+
((Family == AF_Alloca) ? SVB.getAllocaRegionVal(CE, LCtx, Count)
1738+
: SVB.getConjuredHeapSymbolVal(CE, LCtx, Count)
1739+
.castAs<DefinedSVal>());
17381740
State = State->BindExpr(CE, C.getLocationContext(), RetVal);
17391741

17401742
// Fill the region with the initialization value.
@@ -1746,7 +1748,7 @@ ProgramStateRef MallocChecker::MallocMemAux(CheckerContext &C,
17461748

17471749
// Set the region's extent.
17481750
State = setDynamicExtent(State, RetVal.getAsRegion(),
1749-
Size.castAs<DefinedOrUnknownSVal>(), svalBuilder);
1751+
Size.castAs<DefinedOrUnknownSVal>(), SVB);
17501752

17511753
return MallocUpdateRefState(C, CE, State, Family);
17521754
}

clang/lib/StaticAnalyzer/Core/SValBuilder.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,14 @@ SValBuilder::getConjuredHeapSymbolVal(const Expr *E,
231231
return loc::MemRegionVal(MemMgr.getSymbolicHeapRegion(sym));
232232
}
233233

234+
loc::MemRegionVal SValBuilder::getAllocaRegionVal(const Expr *E,
235+
const LocationContext *LCtx,
236+
unsigned VisitCount) {
237+
const AllocaRegion *R =
238+
getRegionManager().getAllocaRegion(E, VisitCount, LCtx);
239+
return loc::MemRegionVal(R);
240+
}
241+
234242
DefinedSVal SValBuilder::getMetadataSymbolVal(const void *symbolTag,
235243
const MemRegion *region,
236244
const Expr *expr, QualType type,

clang/test/Analysis/malloc.c

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -266,13 +266,21 @@ void CheckUseZeroAllocated1(void) {
266266
}
267267

268268
char CheckUseZeroAllocated2(void) {
269+
// NOTE: The `AllocaRegion` that models the return value of `alloca()`
270+
// doesn't have an associated symbol, so the current implementation of
271+
// `MallocChecker::checkUseZeroAllocated()` cannot provide warnings for it.
272+
// However, other checkers like core.uninitialized.UndefReturn (that
273+
// activates in these TCs) or the array bound checkers provide more generic,
274+
// but still sufficient warnings in these cases, so I think it isn't
275+
// important to cover this in MallocChecker.
269276
char *p = alloca(0);
270-
return *p; // expected-warning {{Use of memory allocated with size zero}}
277+
return *p; // expected-warning {{Undefined or garbage value returned to caller}}
271278
}
272279

273280
char CheckUseZeroWinAllocated2(void) {
281+
// Note: Same situation as `CheckUseZeroAllocated2()`.
274282
char *p = _alloca(0);
275-
return *p; // expected-warning {{Use of memory allocated with size zero}}
283+
return *p; // expected-warning {{Undefined or garbage value returned to caller}}
276284
}
277285

278286
void UseZeroAllocated(int *p) {
@@ -727,6 +735,11 @@ void paramFree(int *p) {
727735
myfoo(p); // expected-warning {{Use of memory after it is freed}}
728736
}
729737

738+
void allocaFree(void) {
739+
int *p = alloca(sizeof(int));
740+
free(p); // expected-warning {{Memory allocated by alloca() should not be deallocated}}
741+
}
742+
730743
int* mallocEscapeRet(void) {
731744
int *p = malloc(12);
732745
return p; // no warning

clang/test/Analysis/memory-model.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ void symbolic_malloc() {
9797

9898
void symbolic_alloca() {
9999
int *a = (int *)alloca(12);
100-
clang_analyzer_dump(a); // expected-warning {{Element{HeapSymRegion{conj}}
100+
clang_analyzer_dump(a); // expected-warning {{Element{alloca{}}
101101
clang_analyzer_dumpExtent(a); // expected-warning {{12 S64b}}
102102
clang_analyzer_dumpElementCount(a); // expected-warning {{3 S64b}}
103103
}

clang/test/Analysis/out-of-bounds-diagnostics.c

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -107,12 +107,8 @@ void *alloca(size_t size);
107107
int allocaRegion(void) {
108108
int *mem = (int*)alloca(2*sizeof(int));
109109
mem[3] = -2;
110-
// expected-warning@-1 {{Out of bound access to memory after the end of the heap area}}
111-
// expected-note@-2 {{Access of the heap area at index 3, while it holds only 2 'int' elements}}
112-
// FIXME: this should be
113-
// {{Out of bound access to memory after the end of the memory returned by 'alloca'}}
114-
// {{Access of the memory returned by 'alloca' at index 3, while it holds only 2 'int' elements}}
115-
// but apparently something models 'alloca' as if it was allocating on the heap
110+
// expected-warning@-1 {{Out of bound access to memory after the end of the memory returned by 'alloca'}}
111+
// expected-note@-2 {{Access of the memory returned by 'alloca' at index 3, while it holds only 2 'int' elements}}
116112
return *mem;
117113
}
118114

clang/test/CodeGenCXX/debug-info-static-inline-member.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -49,35 +49,35 @@ int main() {
4949

5050
// CHECK: ![[INT_DECL]] = !DIDerivedType(tag: DW_TAG_member, name: "cexpr_int_with_addr",
5151
// CHECK-SAME: flags: DIFlagStaticMember
52-
// CHECK-NOT: extraData:
52+
// CHECK-SAME: extraData: i32 25
5353

5454
// CHECK: ![[INT_DECL2:[0-9]+]] = !DIDerivedType(tag: DW_TAG_member, name: "cexpr_int2",
5555
// CHECK-SAME: flags: DIFlagStaticMember
56-
// CHECK-NOT: extraData:
56+
// CHECK-SAME: extraData: i32 26
5757

5858
// CHECK: ![[FLOAT_DECL:[0-9]+]] = !DIDerivedType(tag: DW_TAG_member, name: "cexpr_float",
5959
// CHECK-SAME: flags: DIFlagStaticMember
60-
// CHECK-NOT: extraData:
60+
// CHECK-SAME: extraData: float
6161

6262
// CHECK: ![[ENUM_DECL:[0-9]+]] = !DIDerivedType(tag: DW_TAG_member, name: "cexpr_enum",
6363
// CHECK-SAME: flags: DIFlagStaticMember
64-
// CHECK-NOT: extraData:
64+
// CHECK-SAME: extraData: i32 -1
6565

6666
// CHECK: ![[EMPTY_DECL:[0-9]+]] = !DIDerivedType(tag: DW_TAG_member, name: "cexpr_struct_with_addr",
6767
// CHECK-SAME: flags: DIFlagStaticMember
6868
// CHECK-NOT: extraData:
6969

7070
// CHECK: ![[IENUM_DECL:[0-9]+]] = !DIDerivedType(tag: DW_TAG_member, name: "inline_enum",
7171
// CHECK-SAME: flags: DIFlagStaticMember
72-
// CHECK-NOT: extraData:
72+
// CHECK-SAME: extraData: i32 -1
7373

7474
// CHECK: ![[EMPTY_TEMPLATED_DECL:[0-9]+]] = !DIDerivedType(tag: DW_TAG_member, name: "empty_templated",
7575
// CHECK-SAME: flags: DIFlagStaticMember
76-
// CHECK-NOT: extraData:
76+
// CHECK-SAME: extraData: i32 1
7777

7878
// CHECK: ![[TEMPLATE_DECL:[0-9]+]] = !DIDerivedType(tag: DW_TAG_member, name: "cexpr_template",
7979
// CHECK-SAME: flags: DIFlagStaticMember
80-
// CHECK-NOT: extraData:
80+
// CHECK-SAME: extraData: i32 1
8181

8282
// CHECK: !DIGlobalVariableExpression(var: ![[EMPTY_VAR:[0-9]+]], expr: !DIExpression())
8383
// CHECK: ![[EMPTY_VAR]] = distinct !DIGlobalVariable(name: "cexpr_struct_with_addr", linkageName:

clang/test/CodeGenCXX/debug-info-static-member.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,15 +74,15 @@ int C::a = 4;
7474
// CHECK-NOT: align:
7575
// CHECK-NOT: offset:
7676
// CHECK-SAME: flags: DIFlagStaticMember
77-
// CHECK-NOT: extraData:
77+
// CHECK-SAME: extraData: i1 true
7878

7979
// DWARF4: ![[CONST_B_DECL:[0-9]+]] = !DIDerivedType(tag: DW_TAG_member, name: "const_b"
8080
// DWARF5: ![[CONST_B_DECL:[0-9]+]] = !DIDerivedType(tag: DW_TAG_variable, name: "const_b"
8181
// CHECK-NOT: size:
8282
// CHECK-NOT: align:
8383
// CHECK-NOT: offset:
8484
// CHECK-SAME: flags: DIFlagProtected | DIFlagStaticMember
85-
// CHECK-NOT: extraData:
85+
// CHECK-SAME: extraData: float
8686

8787
// DWARF4: ![[DECL_C:[0-9]+]] = !DIDerivedType(tag: DW_TAG_member, name: "c"
8888
// DWARF5: ![[DECL_C:[0-9]+]] = !DIDerivedType(tag: DW_TAG_variable, name: "c"
@@ -97,7 +97,7 @@ int C::a = 4;
9797
// CHECK-NOT: align:
9898
// CHECK-NOT: offset:
9999
// CHECK-SAME: flags: DIFlagPublic | DIFlagStaticMember
100-
// CHECK-NOT: extraData:
100+
// CHECK-SAME: extraData: i32 18
101101
//
102102
// DWARF4: !DIDerivedType(tag: DW_TAG_member, name: "x_a"
103103
// DWARF5: !DIDerivedType(tag: DW_TAG_variable, name: "x_a"
@@ -154,7 +154,7 @@ struct V {
154154
// const_va is not emitted for MS targets.
155155
// NOT-MS: !DIDerivedType(tag: DW_TAG_member, name: "const_va",
156156
// NOT-MS-SAME: line: [[@LINE-5]]
157-
// NOT-MS-NOT: extraData:
157+
// NOT-MS-SAME: extraData: i32 42
158158
const int V::const_va;
159159

160160
namespace x {

flang/lib/Semantics/check-acc-structure.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,13 +218,18 @@ void AccStructureChecker::Leave(const parser::OpenACCCombinedConstruct &x) {
218218
const auto &beginBlockDir{std::get<parser::AccBeginCombinedDirective>(x.t)};
219219
const auto &combinedDir{
220220
std::get<parser::AccCombinedDirective>(beginBlockDir.t)};
221+
auto &doCons{std::get<std::optional<parser::DoConstruct>>(x.t)};
221222
switch (combinedDir.v) {
222223
case llvm::acc::Directive::ACCD_kernels_loop:
223224
case llvm::acc::Directive::ACCD_parallel_loop:
224225
case llvm::acc::Directive::ACCD_serial_loop:
225226
// Restriction - line 1004-1005
226227
CheckOnlyAllowedAfter(llvm::acc::Clause::ACCC_device_type,
227228
computeConstructOnlyAllowedAfterDeviceTypeClauses);
229+
if (doCons) {
230+
const parser::Block &block{std::get<parser::Block>(doCons->t)};
231+
CheckNoBranching(block, GetContext().directive, beginBlockDir.source);
232+
}
228233
break;
229234
default:
230235
break;

flang/test/Parser/acc-unparse.f90

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ program bug47659
99
!$acc parallel loop
1010
do j = 1, 10
1111
if (j == 2) then
12-
exit label1
12+
stop 1
1313
end if
1414
end do
1515
end do label1

flang/test/Semantics/OpenACC/acc-branch.f90

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,27 @@ subroutine openacc_clause_validity
1919
end do
2020
!$acc end parallel
2121

22+
!$acc parallel loop
23+
do i = 1, N
24+
a(i) = 3.14
25+
!ERROR: RETURN statement is not allowed in a PARALLEL LOOP construct
26+
return
27+
end do
28+
29+
!$acc serial loop
30+
do i = 1, N
31+
a(i) = 3.14
32+
!ERROR: RETURN statement is not allowed in a SERIAL LOOP construct
33+
return
34+
end do
35+
36+
!$acc kernels loop
37+
do i = 1, N
38+
a(i) = 3.14
39+
!ERROR: RETURN statement is not allowed in a KERNELS LOOP construct
40+
return
41+
end do
42+
2243
!$acc parallel
2344
!$acc loop
2445
do i = 1, N

llvm/include/llvm/Config/llvm-config.h.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
/* Indicate that this is LLVM compiled from the amd-gfx branch. */
1818
#define LLVM_HAVE_BRANCH_AMD_GFX
19-
#define LLVM_MAIN_REVISION 481976
19+
#define LLVM_MAIN_REVISION 481991
2020

2121
/* Define if LLVM_ENABLE_DUMP is enabled */
2222
#cmakedefine LLVM_ENABLE_DUMP

llvm/lib/Target/AArch64/AArch64SystemOperands.td

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -738,6 +738,7 @@ def : ROSysReg<"ID_AA64PFR1_EL1", 0b11, 0b000, 0b0000, 0b0100, 0b001>;
738738
def : ROSysReg<"ID_AA64PFR2_EL1", 0b11, 0b000, 0b0000, 0b0100, 0b010>;
739739
def : ROSysReg<"ID_AA64DFR0_EL1", 0b11, 0b000, 0b0000, 0b0101, 0b000>;
740740
def : ROSysReg<"ID_AA64DFR1_EL1", 0b11, 0b000, 0b0000, 0b0101, 0b001>;
741+
def : ROSysReg<"ID_AA64DFR2_EL1", 0b11, 0b000, 0b0000, 0b0101, 0b010>;
741742
def : ROSysReg<"ID_AA64AFR0_EL1", 0b11, 0b000, 0b0000, 0b0101, 0b100>;
742743
def : ROSysReg<"ID_AA64AFR1_EL1", 0b11, 0b000, 0b0000, 0b0101, 0b101>;
743744
def : ROSysReg<"ID_AA64ISAR0_EL1", 0b11, 0b000, 0b0000, 0b0110, 0b000>;
@@ -1937,3 +1938,11 @@ let Requires = [{ {AArch64::FeatureFPMR} }] in {
19371938
def : ROSysReg<"ID_AA64FPFR0_EL1", 0b11, 0b000, 0b0000, 0b0100, 0b111>;
19381939
def : RWSysReg<"FPMR", 0b11, 0b011, 0b0100, 0b0100, 0b010>;
19391940
}
1941+
1942+
// v9.5a Software Stepping Enhancements (FEAT_STEP2)
1943+
// Op0 Op1 CRn CRm Op2
1944+
def : RWSysReg<"MDSTEPOP_EL1", 0b10, 0b000, 0b0000, 0b0101, 0b010>;
1945+
1946+
// v9.5a System PMU zero register (FEAT_SPMU2)
1947+
// Op0 Op1 CRn CRm Op2
1948+
def : WOSysReg<"SPMZR_EL0", 0b10, 0b011, 0b1001, 0b1100, 0b100>;

0 commit comments

Comments
 (0)