Skip to content

Commit 817f4e6

Browse files
committed
Merge from 'main' to 'sycl-web' (intel#30)
2 parents 5339876 + 61cdaf6 commit 817f4e6

File tree

108 files changed

+1786
-879
lines changed

Some content is hidden

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

108 files changed

+1786
-879
lines changed

clang-tools-extra/clang-tidy/abseil/DurationRewriter.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ stripFloatLiteralFraction(const MatchFinder::MatchResult &Result,
208208
if (const auto *LitFloat = llvm::dyn_cast<FloatingLiteral>(&Node))
209209
// Attempt to simplify a `Duration` factory call with a literal argument.
210210
if (llvm::Optional<llvm::APSInt> IntValue = truncateIfIntegral(*LitFloat))
211-
return IntValue->toString(/*radix=*/10);
211+
return toString(*IntValue, /*radix=*/10);
212212

213213
return llvm::None;
214214
}

clang-tools-extra/clang-tidy/cppcoreguidelines/NarrowingConversionsCheck.cpp

Lines changed: 49 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,9 @@ void NarrowingConversionsCheck::registerMatchers(MatchFinder *Finder) {
7171
hasType(namedDecl(hasAnyListedName(IgnoreConversionFromTypes)));
7272

7373
// `IsConversionFromIgnoredType` will ignore narrowing calls from those types,
74-
// but not expressions that are promoted to `int64` due to a binary expression
75-
// with one of those types. For example, it will continue to reject:
74+
// but not expressions that are promoted to an ignored type as a result of a
75+
// binary expression with one of those types.
76+
// For example, it will continue to reject:
7677
// `int narrowed = int_value + container.size()`.
7778
// We attempt to address common incidents of compound expressions with
7879
// `IsIgnoredTypeTwoLevelsDeep`, allowing binary expressions that have one
@@ -221,6 +222,22 @@ static bool isWideEnoughToHold(const ASTContext &Context,
221222
return ToIntegerRange.contains(IntegerConstant);
222223
}
223224

225+
// Returns true iff the floating point constant can be losslessly represented
226+
// by an integer in the given destination type. eg. 2.0 can be accurately
227+
// represented by an int32_t, but neither 2^33 nor 2.001 can.
228+
static bool isFloatExactlyRepresentable(const ASTContext &Context,
229+
const llvm::APFloat &FloatConstant,
230+
const QualType &DestType) {
231+
unsigned DestWidth = Context.getIntWidth(DestType);
232+
bool DestSigned = DestType->isSignedIntegerOrEnumerationType();
233+
llvm::APSInt Result = llvm::APSInt(DestWidth, !DestSigned);
234+
bool IsExact = false;
235+
bool Overflows = FloatConstant.convertToInteger(
236+
Result, llvm::APFloat::rmTowardZero, &IsExact) &
237+
llvm::APFloat::opInvalidOp;
238+
return !Overflows && IsExact;
239+
}
240+
224241
static llvm::SmallString<64> getValueAsString(const llvm::APSInt &Value,
225242
uint64_t HexBits) {
226243
llvm::SmallString<64> Str;
@@ -237,6 +254,21 @@ static llvm::SmallString<64> getValueAsString(const llvm::APSInt &Value,
237254
return Str;
238255
}
239256

257+
bool NarrowingConversionsCheck::isWarningInhibitedByEquivalentSize(
258+
const ASTContext &Context, const BuiltinType &FromType,
259+
const BuiltinType &ToType) const {
260+
// With this option, we don't warn on conversions that have equivalent width
261+
// in bits. eg. uint32 <-> int32.
262+
if (!WarnOnEquivalentBitWidth) {
263+
uint64_t FromTypeSize = Context.getTypeSize(&FromType);
264+
uint64_t ToTypeSize = Context.getTypeSize(&ToType);
265+
if (FromTypeSize == ToTypeSize) {
266+
return true;
267+
}
268+
}
269+
return false;
270+
}
271+
240272
void NarrowingConversionsCheck::diagNarrowType(SourceLocation SourceLoc,
241273
const Expr &Lhs,
242274
const Expr &Rhs) {
@@ -351,7 +383,10 @@ void NarrowingConversionsCheck::handleIntegralToFloating(
351383
diagNarrowIntegerConstant(SourceLoc, Lhs, Rhs, IntegerConstant);
352384
return;
353385
}
386+
354387
const BuiltinType *FromType = getBuiltinType(Rhs);
388+
if (isWarningInhibitedByEquivalentSize(Context, *FromType, *ToType))
389+
return;
355390
if (!isWideEnoughToHold(Context, *FromType, *ToType))
356391
diagNarrowType(SourceLoc, Lhs, Rhs);
357392
}
@@ -360,25 +395,21 @@ void NarrowingConversionsCheck::handleFloatingToIntegral(
360395
const ASTContext &Context, SourceLocation SourceLoc, const Expr &Lhs,
361396
const Expr &Rhs) {
362397
llvm::APFloat FloatConstant(0.0);
398+
if (getFloatingConstantExprValue(Context, Rhs, FloatConstant)) {
399+
if (!isFloatExactlyRepresentable(Context, FloatConstant, Lhs.getType()))
400+
return diagNarrowConstant(SourceLoc, Lhs, Rhs);
363401

364-
// We always warn when Rhs is non-constexpr.
365-
if (!getFloatingConstantExprValue(Context, Rhs, FloatConstant))
366-
return diagNarrowType(SourceLoc, Lhs, Rhs);
402+
if (PedanticMode)
403+
return diagConstantCast(SourceLoc, Lhs, Rhs);
367404

368-
QualType DestType = Lhs.getType();
369-
unsigned DestWidth = Context.getIntWidth(DestType);
370-
bool DestSigned = DestType->isSignedIntegerOrEnumerationType();
371-
llvm::APSInt Result = llvm::APSInt(DestWidth, !DestSigned);
372-
bool IsExact = false;
373-
bool Overflows = FloatConstant.convertToInteger(
374-
Result, llvm::APFloat::rmTowardZero, &IsExact) &
375-
llvm::APFloat::opInvalidOp;
376-
// We warn iff the constant floating point value is not exactly representable.
377-
if (Overflows || !IsExact)
378-
return diagNarrowConstant(SourceLoc, Lhs, Rhs);
405+
return;
406+
}
379407

380-
if (PedanticMode)
381-
return diagConstantCast(SourceLoc, Lhs, Rhs);
408+
const BuiltinType *FromType = getBuiltinType(Rhs);
409+
const BuiltinType *ToType = getBuiltinType(Lhs);
410+
if (isWarningInhibitedByEquivalentSize(Context, *FromType, *ToType))
411+
return;
412+
diagNarrowType(SourceLoc, Lhs, Rhs); // Assumed always lossy.
382413
}
383414

384415
void NarrowingConversionsCheck::handleFloatingToBoolean(

clang-tools-extra/clang-tidy/cppcoreguidelines/NarrowingConversionsCheck.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,10 @@ class NarrowingConversionsCheck : public ClangTidyCheck {
9393
void handleBinaryOperator(const ASTContext &Context,
9494
const BinaryOperator &Op);
9595

96+
bool isWarningInhibitedByEquivalentSize(const ASTContext &Context,
97+
const BuiltinType &FromType,
98+
const BuiltinType &ToType) const;
99+
96100
const bool WarnOnIntegerNarrowingConversion;
97101
const bool WarnOnFloatingPointNarrowingConversion;
98102
const bool WarnWithinTemplateInstantiation;

clang-tools-extra/clang-tidy/cppcoreguidelines/ProBoundsConstantArrayIndexCheck.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ void ProBoundsConstantArrayIndexCheck::check(
9999

100100
if (Index->isSigned() && Index->isNegative()) {
101101
diag(Matched->getExprLoc(), "std::array<> index %0 is negative")
102-
<< Index->toString(10);
102+
<< toString(*Index, 10);
103103
return;
104104
}
105105

@@ -118,7 +118,7 @@ void ProBoundsConstantArrayIndexCheck::check(
118118
diag(Matched->getExprLoc(),
119119
"std::array<> index %0 is past the end of the array "
120120
"(which contains %1 elements)")
121-
<< Index->toString(10) << ArraySize.toString(10, false);
121+
<< toString(*Index, 10) << toString(ArraySize, 10, false);
122122
}
123123
}
124124

clang-tools-extra/clangd/DumpAST.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ class DumpVisitor : public RecursiveASTVisitor<DumpVisitor> {
290290
}
291291
std::string getDetail(const TemplateArgumentLoc &TAL) {
292292
if (TAL.getArgument().getKind() == TemplateArgument::Integral)
293-
return TAL.getArgument().getAsIntegral().toString(10);
293+
return toString(TAL.getArgument().getAsIntegral(), 10);
294294
return "";
295295
}
296296
std::string getDetail(const TemplateName &TN) {

clang-tools-extra/clangd/Hover.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -587,7 +587,7 @@ HoverInfo getHoverContents(const NamedDecl *D, const PrintingPolicy &PP,
587587
} else if (const auto *ECD = dyn_cast<EnumConstantDecl>(D)) {
588588
// Dependent enums (e.g. nested in template classes) don't have values yet.
589589
if (!ECD->getType()->isDependentType())
590-
HI.Value = ECD->getInitVal().toString(10);
590+
HI.Value = toString(ECD->getInitVal(), 10);
591591
}
592592

593593
HI.Definition = printDefinition(D, PP);

clang-tools-extra/clangd/refactor/Rename.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -751,6 +751,26 @@ llvm::Expected<RenameResult> rename(const RenameInputs &RInputs) {
751751
auto MainFileRenameEdit = renameWithinFile(AST, RenameDecl, RInputs.NewName);
752752
if (!MainFileRenameEdit)
753753
return MainFileRenameEdit.takeError();
754+
755+
// Check the rename-triggering location is actually being renamed.
756+
// This is a robustness check to avoid surprising rename results -- if the
757+
// the triggering location is not actually the name of the node we identified
758+
// (e.g. for broken code), then rename is likely not what users expect, so we
759+
// reject this kind of rename.
760+
auto StartOffset = positionToOffset(MainFileCode, CurrentIdentifier.start);
761+
auto EndOffset = positionToOffset(MainFileCode, CurrentIdentifier.end);
762+
if (!StartOffset)
763+
return StartOffset.takeError();
764+
if (!EndOffset)
765+
return EndOffset.takeError();
766+
if (llvm::find_if(
767+
*MainFileRenameEdit,
768+
[&StartOffset, &EndOffset](const clang::tooling::Replacement &R) {
769+
return R.getOffset() == *StartOffset &&
770+
R.getLength() == *EndOffset - *StartOffset;
771+
}) == MainFileRenameEdit->end()) {
772+
return makeError(ReasonToReject::NoSymbolFound);
773+
}
754774
RenameResult Result;
755775
Result.Target = CurrentIdentifier;
756776
Edit MainFileEdits = Edit(MainFileCode, std::move(*MainFileRenameEdit));

clang-tools-extra/clangd/unittests/RenameTests.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1071,6 +1071,13 @@ TEST(RenameTest, Renameable) {
10711071
struct B : priv^ate A {};
10721072
)cpp",
10731073
"Cannot rename symbol: there is no symbol at the given location", false},
1074+
{R"cpp(// Ensure it doesn't associate base specifier with base name.
1075+
/*error-ok*/
1076+
struct A {
1077+
A() : inva^lid(0) {}
1078+
};
1079+
)cpp",
1080+
"no symbol", false},
10741081
};
10751082

10761083
for (const auto& Case : Cases) {

clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-narrowing-conversions-equivalentbitwidth-option.cpp

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,35 @@
1111

1212
void narrowing_equivalent_bitwidth() {
1313
int i;
14-
unsigned int j;
15-
i = j;
14+
unsigned int ui;
15+
i = ui;
1616
// CHECK-MESSAGES-DEFAULT: :[[@LINE-1]]:7: warning: narrowing conversion from 'unsigned int' to signed type 'int' is implementation-defined [cppcoreguidelines-narrowing-conversions]
1717
// DISABLED: Warning disabled with WarnOnEquivalentBitWidth=0.
18+
19+
float f;
20+
i = f;
21+
// CHECK-MESSAGES-DEFAULT: :[[@LINE-1]]:7: warning: narrowing conversion from 'float' to 'int' [cppcoreguidelines-narrowing-conversions]
22+
// DISABLED: Warning disabled with WarnOnEquivalentBitWidth=0.
23+
24+
f = i;
25+
// CHECK-MESSAGES-DEFAULT: :[[@LINE-1]]:7: warning: narrowing conversion from 'int' to 'float' [cppcoreguidelines-narrowing-conversions]
26+
// DISABLED: Warning disabled with WarnOnEquivalentBitWidth=0.
27+
28+
long long ll;
29+
double d;
30+
ll = d;
31+
// CHECK-MESSAGES-DEFAULT: :[[@LINE-1]]:8: warning: narrowing conversion from 'double' to 'long long' [cppcoreguidelines-narrowing-conversions]
32+
// DISABLED: Warning disabled with WarnOnEquivalentBitWidth=0.
33+
34+
d = ll;
35+
// CHECK-MESSAGES-DEFAULT: :[[@LINE-1]]:7: warning: narrowing conversion from 'long long' to 'double' [cppcoreguidelines-narrowing-conversions]
36+
// DISABLED: Warning disabled with WarnOnEquivalentBitWidth=0.
1837
}
1938

2039
void most_narrowing_is_not_ok() {
2140
int i;
22-
long long j;
23-
i = j;
41+
long long ui;
42+
i = ui;
2443
// CHECK-MESSAGES-DEFAULT: :[[@LINE-1]]:7: warning: narrowing conversion from 'long long' to signed type 'int' is implementation-defined [cppcoreguidelines-narrowing-conversions]
2544
// CHECK-MESSAGES-DISABLED: :[[@LINE-2]]:7: warning: narrowing conversion from 'long long' to signed type 'int' is implementation-defined [cppcoreguidelines-narrowing-conversions]
2645
}

clang/include/clang/ASTMatchers/ASTMatchers.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1213,7 +1213,7 @@ AST_MATCHER_P(TemplateArgument, equalsIntegralValue,
12131213
std::string, Value) {
12141214
if (Node.getKind() != TemplateArgument::Integral)
12151215
return false;
1216-
return Node.getAsIntegral().toString(10) == Value;
1216+
return toString(Node.getAsIntegral(), 10) == Value;
12171217
}
12181218

12191219
/// Matches an Objective-C autorelease pool statement.

clang/include/clang/Basic/BuiltinsX86_64.def

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ TARGET_BUILTIN(__builtin_ia32_senduipi, "vUWi", "n", "uintr")
103103
// AMX internal builtin
104104
TARGET_BUILTIN(__builtin_ia32_tile_loadconfig_internal, "vvC*", "n", "amx-tile")
105105
TARGET_BUILTIN(__builtin_ia32_tileloadd64_internal, "V256iUsUsvC*z", "n", "amx-tile")
106+
TARGET_BUILTIN(__builtin_ia32_tileloaddt164_internal, "V256iUsUsvC*z", "n", "amx-tile")
106107
TARGET_BUILTIN(__builtin_ia32_tdpbssd_internal, "V256iUsUsUsV256iV256iV256i", "n", "amx-int8")
107108
TARGET_BUILTIN(__builtin_ia32_tdpbsud_internal, "V256iUsUsUsV256iV256iV256i", "n", "amx-int8")
108109
TARGET_BUILTIN(__builtin_ia32_tdpbusd_internal, "V256iUsUsUsV256iV256iV256i", "n", "amx-int8")

0 commit comments

Comments
 (0)