Skip to content

Commit 6417230

Browse files
authored
merge main into amd-staging (#810)
2 parents 7ea86bb + a809a16 commit 6417230

File tree

103 files changed

+2206
-826
lines changed

Some content is hidden

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

103 files changed

+2206
-826
lines changed

clang-tools-extra/clang-tidy/readability/RedundantControlFlowCheck.cpp

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -71,19 +71,11 @@ void RedundantControlFlowCheck::issueDiagnostic(
7171
if (isLocationInMacroExpansion(SM, StmtRange.getBegin()))
7272
return;
7373

74-
const CompoundStmt::const_reverse_body_iterator Previous =
75-
++Block->body_rbegin();
76-
SourceLocation Start;
77-
if (Previous != Block->body_rend())
78-
Start = Lexer::findLocationAfterToken(
79-
cast<Stmt>(*Previous)->getEndLoc(), tok::semi, SM, getLangOpts(),
80-
/*SkipTrailingWhitespaceAndNewLine=*/true);
81-
if (!Start.isValid())
82-
Start = StmtRange.getBegin();
83-
auto RemovedRange = CharSourceRange::getCharRange(
84-
Start, Lexer::findLocationAfterToken(
85-
StmtRange.getEnd(), tok::semi, SM, getLangOpts(),
86-
/*SkipTrailingWhitespaceAndNewLine=*/true));
74+
const auto RemovedRange = CharSourceRange::getCharRange(
75+
StmtRange.getBegin(),
76+
Lexer::findLocationAfterToken(StmtRange.getEnd(), tok::semi, SM,
77+
getLangOpts(),
78+
/*SkipTrailingWhitespaceAndNewLine=*/true));
8779

8880
diag(StmtRange.getBegin(), Diag) << FixItHint::CreateRemoval(RemovedRange);
8981
}

clang-tools-extra/docs/ReleaseNotes.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -586,6 +586,11 @@ Changes in existing checks
586586
<clang-tidy/checks/readability/redundant-casting>` check by fixing false
587587
negatives when explicitly cast from function pointer.
588588

589+
- Improved :doc:`readability-redundant-control-flow
590+
<clang-tidy/checks/readability/redundant-control-flow>` by fixing an issue
591+
where the check would sometimes suggest deleting not only a redundant
592+
``return`` or ``continue``, but also unrelated lines preceding it.
593+
589594
- Improved :doc:`readability-uppercase-literal-suffix
590595
<clang-tidy/checks/readability/uppercase-literal-suffix>` check to recognize
591596
literal suffixes added in C++23 and C23.

clang-tools-extra/test/clang-tidy/checkers/readability/redundant-control-flow.cpp

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,3 +222,53 @@ void call_templates() {
222222
template_loop(10L);
223223
template_loop(10U);
224224
}
225+
226+
void dont_delete_lines_before_return_statement() {
227+
do {} while (0);
228+
#ifdef FOO
229+
#endif
230+
return;
231+
}
232+
// CHECK-MESSAGES: :[[@LINE-2]]:3: warning: redundant return statement
233+
// CHECK-FIXES: void dont_delete_lines_before_return_statement() {
234+
// CHECK-FIXES-NEXT: do {} while (0);
235+
// CHECK-FIXES-NEXT: #ifdef FOO
236+
// CHECK-FIXES-NEXT: #endif
237+
// CHECK-FIXES-NEXT: }
238+
239+
void dont_delete_lines_before_continue_statement() {
240+
for (;;) {
241+
do {} while (0);
242+
#ifdef BAR
243+
#endif
244+
continue;
245+
}
246+
}
247+
// CHECK-MESSAGES: :[[@LINE-3]]:5: warning: redundant continue statement
248+
// CHECK-FIXES: void dont_delete_lines_before_continue_statement() {
249+
// CHECK-FIXES-NEXT: for (;;) {
250+
// CHECK-FIXES-NEXT: do {} while (0);
251+
// CHECK-FIXES-NEXT: #ifdef BAR
252+
// CHECK-FIXES-NEXT: #endif
253+
// CHECK-FIXES-NEXT: }
254+
// CHECK-FIXES-NEXT: }
255+
256+
void semicolon_far_from_return() {
257+
return
258+
259+
;
260+
}
261+
// CHECK-MESSAGES: :[[@LINE-4]]:3: warning: redundant return statement at the end of a function with a void return type [readability-redundant-control-flow]
262+
// CHECK-FIXES: void semicolon_far_from_return() {
263+
// CHECK-FIXES-NEXT: }
264+
265+
void semicolon_far_from_continue() {
266+
for (int i = 0; i < 20; ++i) {
267+
continue
268+
269+
;
270+
}
271+
}
272+
// CHECK-MESSAGES: :[[@LINE-5]]:5: warning: redundant continue statement at the end of loop statement
273+
// CHECK-FIXES: for (int i = 0; i < 20; ++i) {
274+
// CHECK-FIXES-NEXT: }

clang/docs/ReleaseNotes.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -832,6 +832,7 @@ Bug Fixes to C++ Support
832832
- Fix a crash when extracting unavailable member type from alias in template deduction. (#GH165560)
833833
- Fix incorrect diagnostics for lambdas with init-captures inside braced initializers. (#GH163498)
834834
- Fixed spurious diagnoses of certain nested lambda expressions. (#GH149121) (#GH156579)
835+
- Fix the result of ``__is_pointer_interconvertible_base_of`` when arguments are qualified and passed via template parameters. (#GH135273)
835836

836837
Bug Fixes to AST Handling
837838
^^^^^^^^^^^^^^^^^^^^^^^^^

clang/include/clang/AST/CanonicalType.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,8 @@ inline bool operator!=(CanQual<T> x, CanQual<U> y) {
213213
using CanQualType = CanQual<Type>;
214214

215215
inline CanQualType Type::getCanonicalTypeUnqualified() const {
216-
return CanQualType::CreateUnsafe(getCanonicalTypeInternal());
216+
return CanQualType::CreateUnsafe(
217+
getCanonicalTypeInternal().getUnqualifiedType());
217218
}
218219

219220
inline const StreamingDiagnostic &operator<<(const StreamingDiagnostic &DB,

clang/include/clang/CIR/Dialect/IR/CIROps.td

Lines changed: 39 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -425,6 +425,28 @@ def CIR_ConstantOp : CIR_Op<"const", [
425425
return boolAttr.getValue();
426426
llvm_unreachable("Expected a BoolAttr in ConstantOp");
427427
}
428+
429+
bool isAllOnesValue() {
430+
// Check for -1 integers
431+
if (auto intAttr = getValueAttr<cir::IntAttr>())
432+
return intAttr.getValue().isAllOnes();
433+
434+
// Check for FP which are bitcasted from -1 integers
435+
if (auto fpAttr = getValueAttr<cir::FPAttr>())
436+
return fpAttr.getValue().bitcastToAPInt().isAllOnes();
437+
438+
// Check for constant vectors with splat values
439+
if (cir::VectorType v = mlir::dyn_cast<cir::VectorType>(getType()))
440+
if (auto vecAttr = getValueAttr<mlir::DenseElementsAttr>())
441+
if (vecAttr.isSplat()) {
442+
auto splatAttr = vecAttr.getSplatValue<mlir::Attribute>();
443+
if (auto splatInt = mlir::dyn_cast<cir::IntAttr>(splatAttr)) {
444+
return splatInt.getValue().isAllOnes();
445+
}
446+
}
447+
448+
return false;
449+
}
428450
}];
429451

430452
let hasFolder = 1;
@@ -1960,10 +1982,16 @@ def CIR_SelectOp : CIR_Op<"select", [
19601982
let summary = "Yield one of two values based on a boolean value";
19611983
let description = [{
19621984
The `cir.select` operation takes three operands. The first operand
1963-
`condition` is a boolean value of type `!cir.bool`. The second and the third
1964-
operand can be of any CIR types, but their types must be the same. If the
1965-
first operand is `true`, the operation yields its second operand. Otherwise,
1966-
the operation yields its third operand.
1985+
`condition` is either a boolean value of type `!cir.bool` or a boolean
1986+
vector of type `!cir.bool`. The second and the third operand can be of
1987+
any CIR types, but their types must be the same. If the first operand
1988+
is `true`, the operation yields its second operand. Otherwise, the
1989+
operation yields its third operand.
1990+
1991+
In the case where the first operand is a boolean vector, then the second
1992+
and third operand needs to also be of some vectors of the same type to
1993+
each other and that the number of elements of all three operands needs to
1994+
be the same as well.
19671995

19681996
Example:
19691997

@@ -1975,8 +2003,12 @@ def CIR_SelectOp : CIR_Op<"select", [
19752003
```
19762004
}];
19772005

1978-
let arguments = (ins CIR_BoolType:$condition, CIR_AnyType:$true_value,
1979-
CIR_AnyType:$false_value);
2006+
let arguments = (ins
2007+
CIR_ScalarOrVectorOf<CIR_BoolType>:$condition,
2008+
CIR_AnyType:$true_value,
2009+
CIR_AnyType:$false_value
2010+
);
2011+
19802012
let results = (outs CIR_AnyType:$result);
19812013

19822014
let assemblyFormat = [{
@@ -1989,6 +2021,7 @@ def CIR_SelectOp : CIR_Op<"select", [
19892021
}];
19902022

19912023
let hasFolder = 1;
2024+
let hasVerifier = 1;
19922025
}
19932026

19942027
//===----------------------------------------------------------------------===//

clang/include/clang/CIR/Dialect/IR/CIRTypeConstraints.td

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -250,10 +250,10 @@ def CIR_PtrToArray : CIR_PtrToType<CIR_AnyArrayType>;
250250

251251
def CIR_AnyVectorType : CIR_TypeBase<"::cir::VectorType", "vector type">;
252252

253-
def CIR_VectorElementType : AnyTypeOf<[CIR_AnyIntOrFloatType, CIR_AnyPtrType],
254-
"any cir integer, floating point or pointer type"
255-
> {
256-
let cppFunctionName = "isValidVectorTypeElementType";
253+
def CIR_VectorElementType
254+
: AnyTypeOf<[CIR_AnyBoolType, CIR_AnyIntOrFloatType, CIR_AnyPtrType],
255+
"any cir boolean, integer, floating point or pointer type"> {
256+
let cppFunctionName = "isValidVectorTypeElementType";
257257
}
258258

259259
class CIR_ElementTypePred<Pred pred> : SubstLeaves<"$_self",
@@ -266,6 +266,9 @@ class CIR_VectorTypeOf<list<Type> types, string summary = "">
266266
"vector of " # CIR_TypeSummaries<types>.value,
267267
summary)>;
268268

269+
// Type constraint accepting a either a type T or a vector of type T
270+
class CIR_ScalarOrVectorOf<Type T> : AnyTypeOf<[T, CIR_VectorTypeOf<[T]>]>;
271+
269272
// Vector of integral type
270273
def IntegerVector : Type<
271274
And<[

clang/include/clang/CIR/MissingFeatures.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -380,6 +380,9 @@ struct MissingFeatures {
380380

381381
// Future CIR attributes
382382
static bool optInfoAttr() { return false; }
383+
384+
// Maybe only needed for Windows exception handling
385+
static bool currentFuncletPad() { return false; }
383386
};
384387

385388
} // namespace cir

clang/lib/CIR/CodeGen/CIRGenBuiltinX86.cpp

Lines changed: 61 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include "clang/Basic/TargetBuiltins.h"
2121
#include "clang/CIR/Dialect/IR/CIRTypes.h"
2222
#include "clang/CIR/MissingFeatures.h"
23+
#include "llvm/Support/ErrorHandling.h"
2324

2425
using namespace clang;
2526
using namespace clang::CIRGen;
@@ -163,6 +164,41 @@ static mlir::Value emitX86CompressExpand(CIRGenBuilderTy &builder,
163164
mlir::ValueRange{source, mask, maskValue});
164165
}
165166

167+
static mlir::Value getBoolMaskVecValue(CIRGenBuilderTy &builder,
168+
mlir::Location loc, mlir::Value mask,
169+
unsigned numElems) {
170+
171+
cir::BoolType boolTy = builder.getBoolTy();
172+
auto maskTy = cir::VectorType::get(
173+
boolTy, cast<cir::IntType>(mask.getType()).getWidth());
174+
mlir::Value maskVec = builder.createBitcast(mask, maskTy);
175+
176+
if (numElems < 8) {
177+
SmallVector<mlir::Attribute> indices;
178+
indices.reserve(numElems);
179+
mlir::Type i32Ty = builder.getSInt32Ty();
180+
for (auto i : llvm::seq<unsigned>(0, numElems))
181+
indices.push_back(cir::IntAttr::get(i32Ty, i));
182+
183+
maskVec = builder.createVecShuffle(loc, maskVec, maskVec, indices);
184+
}
185+
return maskVec;
186+
}
187+
188+
static mlir::Value emitX86Select(CIRGenBuilderTy &builder, mlir::Location loc,
189+
mlir::Value mask, mlir::Value op0,
190+
mlir::Value op1) {
191+
auto constOp = mlir::dyn_cast_or_null<cir::ConstantOp>(mask.getDefiningOp());
192+
// If the mask is all ones just return first argument.
193+
if (constOp && constOp.isAllOnesValue())
194+
return op0;
195+
196+
mask = getBoolMaskVecValue(builder, loc, mask,
197+
cast<cir::VectorType>(op0.getType()).getSize());
198+
199+
return builder.createSelect(loc, mask, op0, op1);
200+
}
201+
166202
static mlir::Value emitX86MaskAddLogic(CIRGenBuilderTy &builder,
167203
mlir::Location loc,
168204
const std::string &intrinsicName,
@@ -1076,7 +1112,31 @@ mlir::Value CIRGenFunction::emitX86BuiltinExpr(unsigned builtinID,
10761112
case X86::BI__builtin_ia32_extractf64x2_256_mask:
10771113
case X86::BI__builtin_ia32_extracti64x2_256_mask:
10781114
case X86::BI__builtin_ia32_extractf64x2_512_mask:
1079-
case X86::BI__builtin_ia32_extracti64x2_512_mask:
1115+
case X86::BI__builtin_ia32_extracti64x2_512_mask: {
1116+
mlir::Location loc = getLoc(expr->getExprLoc());
1117+
cir::VectorType dstTy = cast<cir::VectorType>(convertType(expr->getType()));
1118+
unsigned numElts = dstTy.getSize();
1119+
unsigned srcNumElts = cast<cir::VectorType>(ops[0].getType()).getSize();
1120+
unsigned subVectors = srcNumElts / numElts;
1121+
assert(llvm::isPowerOf2_32(subVectors) && "Expected power of 2 subvectors");
1122+
unsigned index =
1123+
ops[1].getDefiningOp<cir::ConstantOp>().getIntValue().getZExtValue();
1124+
1125+
index &= subVectors - 1; // Remove any extra bits.
1126+
index *= numElts;
1127+
1128+
int64_t indices[16];
1129+
std::iota(indices, indices + numElts, index);
1130+
1131+
mlir::Value poison =
1132+
builder.getConstant(loc, cir::PoisonAttr::get(ops[0].getType()));
1133+
mlir::Value res = builder.createVecShuffle(loc, ops[0], poison,
1134+
ArrayRef(indices, numElts));
1135+
if (ops.size() == 4)
1136+
res = emitX86Select(builder, loc, ops[3], res, ops[2]);
1137+
1138+
return res;
1139+
}
10801140
case X86::BI__builtin_ia32_vinsertf128_pd256:
10811141
case X86::BI__builtin_ia32_vinsertf128_ps256:
10821142
case X86::BI__builtin_ia32_vinsertf128_si256:

clang/lib/CIR/CodeGen/CIRGenCXXABI.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,9 @@ class CIRGenCXXABI {
126126

127127
virtual void emitBadCastCall(CIRGenFunction &cgf, mlir::Location loc) = 0;
128128

129+
virtual void emitBeginCatch(CIRGenFunction &cgf,
130+
const CXXCatchStmt *catchStmt) = 0;
131+
129132
virtual mlir::Attribute getAddrOfRTTIDescriptor(mlir::Location loc,
130133
QualType ty) = 0;
131134

0 commit comments

Comments
 (0)