Skip to content

Commit 481ed31

Browse files
SC llvm teamSC llvm team
authored andcommitted
Merged main:c14ca4c16c22 into amd-gfx:6385230779ab
Local branch amd-gfx 6385230 Merged main:1a4b9b6f7339 into amd-gfx:31ed504cc6fe Remote branch main c14ca4c [clang] set DebugCompilationDir in PCHContainer (llvm#67744)
2 parents 6385230 + c14ca4c commit 481ed31

File tree

15 files changed

+110
-183
lines changed

15 files changed

+110
-183
lines changed

clang/lib/CodeGen/ObjectFilePCHContainerOperations.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,8 @@ class PCHContainerGenerator : public ASTConsumer {
161161
CodeGenOpts.setDebugInfo(llvm::codegenoptions::FullDebugInfo);
162162
CodeGenOpts.setDebuggerTuning(CI.getCodeGenOpts().getDebuggerTuning());
163163
CodeGenOpts.DwarfVersion = CI.getCodeGenOpts().DwarfVersion;
164+
CodeGenOpts.DebugCompilationDir =
165+
CI.getInvocation().getCodeGenOpts().DebugCompilationDir;
164166
CodeGenOpts.DebugPrefixMap =
165167
CI.getInvocation().getCodeGenOpts().DebugPrefixMap;
166168
CodeGenOpts.DebugStrictDwarf = CI.getCodeGenOpts().DebugStrictDwarf;

clang/lib/StaticAnalyzer/Checkers/UndefResultChecker.cpp

Lines changed: 3 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -115,59 +115,9 @@ void UndefResultChecker::checkPostStmt(const BinaryOperator *B,
115115
OS << " due to array index out of bounds";
116116
} else {
117117
// Neither operand was undefined, but the result is undefined.
118-
if ((B->getOpcode() == BinaryOperatorKind::BO_Shl ||
119-
B->getOpcode() == BinaryOperatorKind::BO_Shr) &&
120-
C.isNegative(B->getRHS())) {
121-
OS << "The result of the "
122-
<< ((B->getOpcode() == BinaryOperatorKind::BO_Shl) ? "left"
123-
: "right")
124-
<< " shift is undefined because the right operand is negative";
125-
Ex = B->getRHS();
126-
} else if ((B->getOpcode() == BinaryOperatorKind::BO_Shl ||
127-
B->getOpcode() == BinaryOperatorKind::BO_Shr) &&
128-
isShiftOverflow(B, C)) {
129-
130-
OS << "The result of the "
131-
<< ((B->getOpcode() == BinaryOperatorKind::BO_Shl) ? "left"
132-
: "right")
133-
<< " shift is undefined due to shifting by ";
134-
Ex = B->getRHS();
135-
136-
SValBuilder &SB = C.getSValBuilder();
137-
const llvm::APSInt *I =
138-
SB.getKnownValue(C.getState(), C.getSVal(B->getRHS()));
139-
if (!I)
140-
OS << "a value that is";
141-
else if (I->isUnsigned())
142-
OS << '\'' << I->getZExtValue() << "\', which is";
143-
else
144-
OS << '\'' << I->getSExtValue() << "\', which is";
145-
146-
OS << " greater or equal to the width of type '"
147-
<< B->getLHS()->getType() << "'.";
148-
} else if (B->getOpcode() == BinaryOperatorKind::BO_Shl &&
149-
C.isNegative(B->getLHS())) {
150-
OS << "The result of the left shift is undefined because the left "
151-
"operand is negative";
152-
Ex = B->getLHS();
153-
} else if (B->getOpcode() == BinaryOperatorKind::BO_Shl &&
154-
isLeftShiftResultUnrepresentable(B, C)) {
155-
ProgramStateRef State = C.getState();
156-
SValBuilder &SB = C.getSValBuilder();
157-
const llvm::APSInt *LHS =
158-
SB.getKnownValue(State, C.getSVal(B->getLHS()));
159-
const llvm::APSInt *RHS =
160-
SB.getKnownValue(State, C.getSVal(B->getRHS()));
161-
OS << "The result of the left shift is undefined due to shifting \'"
162-
<< LHS->getSExtValue() << "\' by \'" << RHS->getZExtValue()
163-
<< "\', which is unrepresentable in the unsigned version of "
164-
<< "the return type \'" << B->getLHS()->getType() << "\'";
165-
Ex = B->getLHS();
166-
} else {
167-
OS << "The result of the '"
168-
<< BinaryOperator::getOpcodeStr(B->getOpcode())
169-
<< "' expression is undefined";
170-
}
118+
OS << "The result of the '"
119+
<< BinaryOperator::getOpcodeStr(B->getOpcode())
120+
<< "' expression is undefined";
171121
}
172122
auto report = std::make_unique<PathSensitiveBugReport>(*BT, OS.str(), N);
173123
if (Ex) {

clang/lib/StaticAnalyzer/Core/BasicValueFactory.cpp

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -280,14 +280,6 @@ BasicValueFactory::evalAPSInt(BinaryOperator::Opcode Op,
280280
if (Amt >= V1.getBitWidth())
281281
return nullptr;
282282

283-
if (!Ctx.getLangOpts().CPlusPlus20) {
284-
if (V1.isSigned() && V1.isNegative())
285-
return nullptr;
286-
287-
if (V1.isSigned() && Amt > V1.countl_zero())
288-
return nullptr;
289-
}
290-
291283
return &getValue( V1.operator<<( (unsigned) Amt ));
292284
}
293285

clang/lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -529,8 +529,21 @@ SVal SimpleSValBuilder::evalBinOpNN(ProgramStateRef state,
529529

530530
const llvm::APSInt *Result =
531531
BasicVals.evalAPSInt(op, LHSValue, RHSValue);
532-
if (!Result)
532+
if (!Result) {
533+
if (op == BO_Shl || op == BO_Shr) {
534+
// FIXME: At this point the constant folding claims that the result
535+
// of a bitwise shift is undefined. However, constant folding
536+
// relies on the inaccurate type information that is stored in the
537+
// bit size of APSInt objects, and if we reached this point, then
538+
// the checker core.BitwiseShift already determined that the shift
539+
// is valid (in a PreStmt callback, by querying the real type from
540+
// the AST node).
541+
// To avoid embarrassing false positives, let's just say that we
542+
// don't know anything about the result of the shift.
543+
return UnknownVal();
544+
}
533545
return UndefinedVal();
546+
}
534547

535548
return nonloc::ConcreteInt(*Result);
536549
}

clang/test/Analysis/bitwise-ops-nocrash.c

Lines changed: 0 additions & 28 deletions
This file was deleted.

clang/test/Analysis/bitwise-ops.c

Lines changed: 0 additions & 60 deletions
This file was deleted.

clang/test/Analysis/bitwise-shift-sanity-checks.c

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
1-
// RUN: %clang_analyze_cc1 -analyzer-checker=core.BitwiseShift \
1+
// RUN: %clang_analyze_cc1 -analyzer-checker=core \
22
// RUN: -analyzer-config core.BitwiseShift:Pedantic=true \
33
// RUN: -verify=expected,pedantic \
44
// RUN: -triple x86_64-pc-linux-gnu -x c %s \
55
// RUN: -Wno-shift-count-negative -Wno-shift-negative-value \
66
// RUN: -Wno-shift-count-overflow -Wno-shift-overflow \
77
// RUN: -Wno-shift-sign-overflow
88
//
9-
// RUN: %clang_analyze_cc1 -analyzer-checker=core.BitwiseShift \
9+
// RUN: %clang_analyze_cc1 -analyzer-checker=core \
1010
// RUN: -analyzer-config core.BitwiseShift:Pedantic=true \
1111
// RUN: -verify=expected,pedantic \
1212
// RUN: -triple x86_64-pc-linux-gnu -x c++ -std=c++14 %s \
1313
// RUN: -Wno-shift-count-negative -Wno-shift-negative-value \
1414
// RUN: -Wno-shift-count-overflow -Wno-shift-overflow \
1515
// RUN: -Wno-shift-sign-overflow
1616
//
17-
// RUN: %clang_analyze_cc1 -analyzer-checker=core.BitwiseShift \
17+
// RUN: %clang_analyze_cc1 -analyzer-checker=core \
1818
// RUN: -verify=expected \
1919
// RUN: -triple x86_64-pc-linux-gnu -x c++ -std=c++20 %s \
2020
// RUN: -Wno-shift-count-negative -Wno-shift-negative-value \
@@ -23,6 +23,8 @@
2323

2424
// This test file verifies that the BitwiseShift checker does not crash or
2525
// report false positives (at least on the cases that are listed here...)
26+
// Other core checkers are also enabled to see interactions with e.g.
27+
// core.UndefinedBinaryOperatorResult.
2628
// For the sake of brevity, 'note' output is not checked in this file.
2729

2830
// TEST OBVIOUSLY CORRECT CODE
@@ -116,3 +118,17 @@ void doubles_cast_to_integer(int *c) {
116118
*c = ((int)1.5) << 1; // no-crash
117119
*c = ((int)1.5) << (int)1.5; // no-crash
118120
}
121+
122+
// TEST CODE THAT WAS TRIGGERING BUGS IN EARLIER REVISIONS
123+
//===----------------------------------------------------------------------===//
124+
125+
unsigned int strange_cast(unsigned short sh) {
126+
// This testcase triggers a bug in the constant folding (it "forgets" the
127+
// cast), which is silenced in SimpleSValBuilder::evalBinOpNN() with an ugly
128+
// workaround, because otherwise it would lead to a false positive from
129+
// core.UndefinedBinaryOperatorResult.
130+
unsigned int i;
131+
sh++;
132+
for (i=0; i<sh; i++) {}
133+
return (unsigned int) ( ((unsigned int) sh) << 16 ); // no-warning
134+
}

clang/test/Analysis/left-shift-cxx2a.cpp

Lines changed: 0 additions & 22 deletions
This file was deleted.

clang/test/Analysis/svalbuilder-simplify-no-crash.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,10 @@
66
// Here, we test that svalbuilder simplification does not produce any
77
// assertion failure.
88

9+
// expected-no-diagnostics
10+
911
void crashing(long a, _Bool b) {
1012
(void)(a & 1 && 0);
1113
b = a & 1;
12-
(void)(b << 1); // expected-warning{{core.UndefinedBinaryOperatorResult}}
14+
(void)(b << 1);
1315
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// UNSUPPORTED: target={{.*}}-zos{{.*}}, target={{.*}}-aix{{.*}}
2+
// REQUIRES: asserts
3+
4+
// Modules:
5+
// RUN: rm -rf %t
6+
// RUN: %clang_cc1 -x objective-c -fmodules -fmodule-format=obj \
7+
// RUN: -fdebug-compilation-dir=/OVERRIDE \
8+
// RUN: -fimplicit-module-maps -DMODULES -fmodules-cache-path=%t %s \
9+
// RUN: -I %S/Inputs -I %t -emit-llvm -o %t.ll \
10+
// RUN: -mllvm -debug-only=pchcontainer &>%t-mod.ll
11+
// RUN: cat %t-mod.ll | FileCheck %s
12+
13+
// PCH:
14+
// RUN: %clang_cc1 -x objective-c -emit-pch -fmodule-format=obj -I %S/Inputs \
15+
// RUN: -fdebug-compilation-dir=/OVERRIDE \
16+
// RUN: -o %t.pch %S/Inputs/DebugObjC.h \
17+
// RUN: -mllvm -debug-only=pchcontainer &>%t-pch.ll
18+
// RUN: cat %t-pch.ll | FileCheck %s
19+
20+
#ifdef MODULES
21+
@import DebugObjC;
22+
#endif
23+
24+
// CHECK: !DIFile(filename: "{{.*}}DebugObjC{{(\.h)?}}", directory: "/OVERRIDE")

libc/cmake/modules/LLVMLibCTestRules.cmake

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -525,7 +525,11 @@ function(add_integration_test test_name)
525525
--target=${LIBC_GPU_TARGET_TRIPLE})
526526
endif()
527527

528-
target_link_options(${fq_build_target_name} PRIVATE -nolibc -nostartfiles -nostdlib++ -static)
528+
if(LIBC_TARGET_ARCHITECTURE_IS_GPU)
529+
target_link_options(${fq_build_target_name} PRIVATE -nostdlib -static)
530+
else()
531+
target_link_options(${fq_build_target_name} PRIVATE -nolibc -nostartfiles -nostdlib++ -static)
532+
endif()
529533
target_link_libraries(
530534
${fq_build_target_name}
531535
# The NVIDIA 'nvlink' linker does not currently support static libraries.

libc/test/integration/startup/gpu/init_fini_array_test.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,18 +37,18 @@ A global(GLOBAL_INDEX, INITVAL_INITIALIZER);
3737
int initval = 0;
3838
int before = 0;
3939

40-
__attribute__((constructor(101))) void run_before() {
40+
__attribute__((constructor(101))) void run_before(int, char **, char **) {
4141
before = BEFORE_INITIALIZER;
4242
}
4343

44-
__attribute__((constructor(65535))) void run_after() {
44+
__attribute__((constructor(65535))) void run_after(int, char **, char **) {
4545
ASSERT_EQ(before, BEFORE_INITIALIZER);
4646
}
4747

4848
__attribute__((constructor)) void set_initval() {
4949
initval = INITVAL_INITIALIZER;
5050
}
51-
__attribute__((destructor(1))) void reset_initval() {
51+
__attribute__((destructor(101))) void reset_initval() {
5252
ASSERT_TRUE(global_destroyed);
5353
initval = 0;
5454
}

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 476399
19+
#define LLVM_MAIN_REVISION 476404
2020

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

mlir/lib/Dialect/Linalg/IR/LinalgOps.cpp

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2387,8 +2387,23 @@ LogicalResult SoftmaxOp::fold(FoldAdaptor, SmallVectorImpl<OpFoldResult> &) {
23872387
LogicalResult
23882388
SoftmaxOp::reifyResultShapes(OpBuilder &b,
23892389
ReifiedRankedShapedTypeDims &reifiedReturnShapes) {
2390-
return cast<LinalgOp>(getOperation())
2391-
.reifyResultShapes(b, reifiedReturnShapes);
2390+
SmallVector<OpFoldResult> shapes;
2391+
Location loc = getOperation()->getLoc();
2392+
IRRewriter rewriter(b);
2393+
auto inputShapedType = llvm::cast<ShapedType>(getInputOperandType());
2394+
auto outputShapedType = llvm::cast<ShapedType>(getOutputOperandType());
2395+
for (int64_t dim : llvm::seq<int64_t>(0, getOutputOperandRank())) {
2396+
if (!outputShapedType.isDynamicDim(dim)) {
2397+
// Static dim: Return IntegerAttr.
2398+
shapes.push_back(b.getIndexAttr(inputShapedType.getDimSize(dim)));
2399+
} else {
2400+
// Dynamic dim: Return Value.
2401+
OpFoldResult ofr = createOrFoldDimOp(b, loc, getInput(), dim);
2402+
shapes.push_back(getValueOrCreateConstantIndexOp(b, loc, ofr));
2403+
}
2404+
}
2405+
reifiedReturnShapes.emplace_back(std::move(shapes));
2406+
return success();
23922407
}
23932408

23942409
void SoftmaxOp::getEffects(

0 commit comments

Comments
 (0)