Skip to content

Commit e4dbc0b

Browse files
author
Jenkins
committed
merge main into amd-staging
Change-Id: I35080ebbca3b6ae552c6161553ff9ae9ac1752d8
2 parents 1d8cbac + 7249692 commit e4dbc0b

File tree

43 files changed

+882
-226
lines changed

Some content is hidden

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

43 files changed

+882
-226
lines changed

clang-tools-extra/clang-tidy/modernize/UseOverrideCheck.cpp

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
//===----------------------------------------------------------------------===//
88

99
#include "UseOverrideCheck.h"
10+
#include "../utils/LexerUtils.h"
1011
#include "clang/AST/ASTContext.h"
1112
#include "clang/ASTMatchers/ASTMatchFinder.h"
1213
#include "clang/Lex/Lexer.h"
@@ -228,9 +229,14 @@ void UseOverrideCheck::check(const MatchFinder::MatchResult &Result) {
228229
if (HasVirtual) {
229230
for (Token Tok : Tokens) {
230231
if (Tok.is(tok::kw_virtual)) {
231-
Diag << FixItHint::CreateRemoval(CharSourceRange::getTokenRange(
232-
Tok.getLocation(), Tok.getLocation()));
233-
break;
232+
std::optional<Token> NextToken =
233+
utils::lexer::findNextTokenIncludingComments(
234+
Tok.getEndLoc(), Sources, getLangOpts());
235+
if (NextToken.has_value()) {
236+
Diag << FixItHint::CreateRemoval(CharSourceRange::getCharRange(
237+
Tok.getLocation(), NextToken->getLocation()));
238+
break;
239+
}
234240
}
235241
}
236242
}

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

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -898,6 +898,46 @@ TEST(DiagnosticTest, ClangTidySelfContainedDiags) {
898898
withFix(equalToFix(ExpectedDFix))))));
899899
}
900900

901+
TEST(DiagnosticTest, ClangTidySelfContainedDiagsFormatting) {
902+
Annotations Main(R"cpp(
903+
class Interface {
904+
public:
905+
virtual void Reset1() = 0;
906+
virtual void Reset2() = 0;
907+
};
908+
class A : public Interface {
909+
// This will be marked by clangd to use override instead of virtual
910+
$virtual1[[virtual ]]void $Reset1[[Reset1]]()$override1[[]];
911+
$virtual2[[virtual ]]/**/void $Reset2[[Reset2]]()$override2[[]];
912+
};
913+
)cpp");
914+
TestTU TU = TestTU::withCode(Main.code());
915+
TU.ClangTidyProvider =
916+
addTidyChecks("cppcoreguidelines-explicit-virtual-functions,");
917+
clangd::Fix const ExpectedFix1{
918+
"prefer using 'override' or (rarely) 'final' "
919+
"instead of 'virtual'",
920+
{TextEdit{Main.range("override1"), " override"},
921+
TextEdit{Main.range("virtual1"), ""}}};
922+
clangd::Fix const ExpectedFix2{
923+
"prefer using 'override' or (rarely) 'final' "
924+
"instead of 'virtual'",
925+
{TextEdit{Main.range("override2"), " override"},
926+
TextEdit{Main.range("virtual2"), ""}}};
927+
// Note that in the Fix we expect the "virtual" keyword and the following
928+
// whitespace to be deleted
929+
EXPECT_THAT(TU.build().getDiagnostics(),
930+
ifTidyChecks(UnorderedElementsAre(
931+
AllOf(Diag(Main.range("Reset1"),
932+
"prefer using 'override' or (rarely) 'final' "
933+
"instead of 'virtual'"),
934+
withFix(equalToFix(ExpectedFix1))),
935+
AllOf(Diag(Main.range("Reset2"),
936+
"prefer using 'override' or (rarely) 'final' "
937+
"instead of 'virtual'"),
938+
withFix(equalToFix(ExpectedFix2))))));
939+
}
940+
901941
TEST(DiagnosticsTest, Preprocessor) {
902942
// This looks like a preamble, but there's an #else in the middle!
903943
// Check that:

clang-tools-extra/docs/ReleaseNotes.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,10 @@ Changes in existing checks
164164
`AllowStringArrays` option, enabling the exclusion of array types with deduced
165165
length initialized from string literals.
166166

167+
- Improved :doc:`modernize-use-override
168+
<clang-tidy/checks/modernize/use-override>` check to also remove any trailing
169+
whitespace when deleting the ``virtual`` keyword.
170+
167171
- Improved :doc:`readability-redundant-inline-specifier
168172
<clang-tidy/checks/readability/redundant-inline-specifier>` check to properly
169173
emit warnings for static data member with an in-class initializer.

clang-tools-extra/test/clang-tidy/checkers/modernize/use-override.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ struct Base {
2727
virtual void f() = 0;
2828
virtual void f2() const = 0;
2929
virtual void g() = 0;
30+
virtual void g2() = 0;
3031

3132
virtual void j() const;
3233
virtual MustUseResultObject k();
@@ -126,6 +127,10 @@ struct SimpleCases : public Base {
126127
virtual void t() throw();
127128
// CHECK-MESSAGES: :[[@LINE-1]]:16: warning: prefer using
128129
// CHECK-FIXES: {{^}} void t() throw() override;
130+
131+
virtual /* */ void g2();
132+
// CHECK-MESSAGES: :[[@LINE-1]]:33: warning: prefer using 'override' or (rarely) 'final' instead of 'virtual'
133+
// CHECK-FIXES: {{^}} /* */ void g2() override;
129134
};
130135

131136
// CHECK-MESSAGES-NOT: warning:

clang/docs/ReleaseNotes.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,12 @@ DWARF Support in Clang
315315
Floating Point Support in Clang
316316
-------------------------------
317317

318+
Fixed Point Support in Clang
319+
----------------------------
320+
321+
- Support fixed point precision macros according to ``7.18a.3`` of
322+
`ISO/IEC TR 18037:2008 <https://standards.iso.org/ittf/PubliclyAvailableStandards/c051126_ISO_IEC_TR_18037_2008.zip>`_.
323+
318324
AST Matchers
319325
------------
320326

clang/lib/Frontend/InitPreprocessor.cpp

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -768,6 +768,60 @@ void InitializeOpenCLFeatureTestMacros(const TargetInfo &TI,
768768
Builder.defineMacro("__opencl_c_int64");
769769
}
770770

771+
llvm::SmallString<32> ConstructFixedPointLiteral(llvm::APFixedPoint Val,
772+
llvm::StringRef Suffix) {
773+
if (Val.isSigned() && Val == llvm::APFixedPoint::getMin(Val.getSemantics())) {
774+
// When representing the min value of a signed fixed point type in source
775+
// code, we cannot simply write `-<lowest value>`. For example, the min
776+
// value of a `short _Fract` cannot be written as `-1.0hr`. This is because
777+
// the parser will read this (and really any negative numerical literal) as
778+
// a UnaryOperator that owns a FixedPointLiteral with a positive value
779+
// rather than just a FixedPointLiteral with a negative value. Compiling
780+
// `-1.0hr` results in an overflow to the maximal value of that fixed point
781+
// type. The correct way to represent a signed min value is to instead split
782+
// it into two halves, like `(-0.5hr-0.5hr)` which is what the standard
783+
// defines SFRACT_MIN as.
784+
llvm::SmallString<32> Literal;
785+
Literal.push_back('(');
786+
llvm::SmallString<32> HalfStr =
787+
ConstructFixedPointLiteral(Val.shr(1), Suffix);
788+
Literal += HalfStr;
789+
Literal += HalfStr;
790+
Literal.push_back(')');
791+
return Literal;
792+
}
793+
794+
llvm::SmallString<32> Str(Val.toString());
795+
Str += Suffix;
796+
return Str;
797+
}
798+
799+
void DefineFixedPointMacros(const TargetInfo &TI, MacroBuilder &Builder,
800+
llvm::StringRef TypeName, llvm::StringRef Suffix,
801+
unsigned Width, unsigned Scale, bool Signed) {
802+
// Saturation doesn't affect the size or scale of a fixed point type, so we
803+
// don't need it here.
804+
llvm::FixedPointSemantics FXSema(
805+
Width, Scale, Signed, /*IsSaturated=*/false,
806+
!Signed && TI.doUnsignedFixedPointTypesHavePadding());
807+
llvm::SmallString<32> MacroPrefix("__");
808+
MacroPrefix += TypeName;
809+
Builder.defineMacro(MacroPrefix + "_EPSILON__",
810+
ConstructFixedPointLiteral(
811+
llvm::APFixedPoint::getEpsilon(FXSema), Suffix));
812+
Builder.defineMacro(MacroPrefix + "_FBIT__", Twine(Scale));
813+
Builder.defineMacro(
814+
MacroPrefix + "_MAX__",
815+
ConstructFixedPointLiteral(llvm::APFixedPoint::getMax(FXSema), Suffix));
816+
817+
// ISO/IEC TR 18037:2008 doesn't specify MIN macros for unsigned types since
818+
// they're all just zero.
819+
if (Signed)
820+
Builder.defineMacro(
821+
MacroPrefix + "_MIN__",
822+
ConstructFixedPointLiteral(llvm::APFixedPoint::getMin(FXSema), Suffix));
823+
}
824+
771825
static void InitializePredefinedMacros(const TargetInfo &TI,
772826
const LangOptions &LangOpts,
773827
const FrontendOptions &FEOpts,
@@ -1097,6 +1151,47 @@ static void InitializePredefinedMacros(const TargetInfo &TI,
10971151
TI.getTypeWidth(TI.getIntMaxType()) &&
10981152
"uintmax_t and intmax_t have different widths?");
10991153

1154+
if (LangOpts.FixedPoint) {
1155+
// Each unsigned type has the same width as their signed type.
1156+
DefineFixedPointMacros(TI, Builder, "SFRACT", "HR", TI.getShortFractWidth(),
1157+
TI.getShortFractScale(), /*Signed=*/true);
1158+
DefineFixedPointMacros(TI, Builder, "USFRACT", "UHR",
1159+
TI.getShortFractWidth(),
1160+
TI.getUnsignedShortFractScale(), /*Signed=*/false);
1161+
DefineFixedPointMacros(TI, Builder, "FRACT", "R", TI.getFractWidth(),
1162+
TI.getFractScale(), /*Signed=*/true);
1163+
DefineFixedPointMacros(TI, Builder, "UFRACT", "UR", TI.getFractWidth(),
1164+
TI.getUnsignedFractScale(), /*Signed=*/false);
1165+
DefineFixedPointMacros(TI, Builder, "LFRACT", "LR", TI.getLongFractWidth(),
1166+
TI.getLongFractScale(), /*Signed=*/true);
1167+
DefineFixedPointMacros(TI, Builder, "ULFRACT", "ULR",
1168+
TI.getLongFractWidth(),
1169+
TI.getUnsignedLongFractScale(), /*Signed=*/false);
1170+
DefineFixedPointMacros(TI, Builder, "SACCUM", "HK", TI.getShortAccumWidth(),
1171+
TI.getShortAccumScale(), /*Signed=*/true);
1172+
DefineFixedPointMacros(TI, Builder, "USACCUM", "UHK",
1173+
TI.getShortAccumWidth(),
1174+
TI.getUnsignedShortAccumScale(), /*Signed=*/false);
1175+
DefineFixedPointMacros(TI, Builder, "ACCUM", "K", TI.getAccumWidth(),
1176+
TI.getAccumScale(), /*Signed=*/true);
1177+
DefineFixedPointMacros(TI, Builder, "UACCUM", "UK", TI.getAccumWidth(),
1178+
TI.getUnsignedAccumScale(), /*Signed=*/false);
1179+
DefineFixedPointMacros(TI, Builder, "LACCUM", "LK", TI.getLongAccumWidth(),
1180+
TI.getLongAccumScale(), /*Signed=*/true);
1181+
DefineFixedPointMacros(TI, Builder, "ULACCUM", "ULK",
1182+
TI.getLongAccumWidth(),
1183+
TI.getUnsignedLongAccumScale(), /*Signed=*/false);
1184+
1185+
Builder.defineMacro("__SACCUM_IBIT__", Twine(TI.getShortAccumIBits()));
1186+
Builder.defineMacro("__USACCUM_IBIT__",
1187+
Twine(TI.getUnsignedShortAccumIBits()));
1188+
Builder.defineMacro("__ACCUM_IBIT__", Twine(TI.getAccumIBits()));
1189+
Builder.defineMacro("__UACCUM_IBIT__", Twine(TI.getUnsignedAccumIBits()));
1190+
Builder.defineMacro("__LACCUM_IBIT__", Twine(TI.getLongAccumIBits()));
1191+
Builder.defineMacro("__ULACCUM_IBIT__",
1192+
Twine(TI.getUnsignedLongAccumIBits()));
1193+
}
1194+
11001195
if (TI.hasFloat16Type())
11011196
DefineFloatMacros(Builder, "FLT16", &TI.getHalfFormat(), "F16");
11021197
DefineFloatMacros(Builder, "FLT", &TI.getFloatFormat(), "F");

clang/lib/StaticAnalyzer/Checkers/WebKit/ASTUtils.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ namespace clang {
1919
std::pair<const Expr *, bool>
2020
tryToFindPtrOrigin(const Expr *E, bool StopAtFirstRefCountedObj) {
2121
while (E) {
22+
if (auto *tempExpr = dyn_cast<MaterializeTemporaryExpr>(E)) {
23+
E = tempExpr->getSubExpr();
24+
continue;
25+
}
2226
if (auto *cast = dyn_cast<CastExpr>(E)) {
2327
if (StopAtFirstRefCountedObj) {
2428
if (auto *ConversionFunc =
@@ -62,6 +66,8 @@ tryToFindPtrOrigin(const Expr *E, bool StopAtFirstRefCountedObj) {
6266
E = call->getArg(0);
6367
continue;
6468
}
69+
if (isReturnValueRefCounted(callee))
70+
return {E, true};
6571

6672
if (isPtrConversion(callee)) {
6773
E = call->getArg(0);

clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,26 @@ bool isCtorOfRefCounted(const clang::FunctionDecl *F) {
119119
|| FunctionName == "Identifier";
120120
}
121121

122+
bool isReturnValueRefCounted(const clang::FunctionDecl *F) {
123+
assert(F);
124+
QualType type = F->getReturnType();
125+
while (!type.isNull()) {
126+
if (auto *elaboratedT = type->getAs<ElaboratedType>()) {
127+
type = elaboratedT->desugar();
128+
continue;
129+
}
130+
if (auto *specialT = type->getAs<TemplateSpecializationType>()) {
131+
if (auto *decl = specialT->getTemplateName().getAsTemplateDecl()) {
132+
auto name = decl->getNameAsString();
133+
return name == "Ref" || name == "RefPtr";
134+
}
135+
return false;
136+
}
137+
return false;
138+
}
139+
return false;
140+
}
141+
122142
std::optional<bool> isUncounted(const CXXRecordDecl* Class)
123143
{
124144
// Keep isRefCounted first as it's cheaper.
@@ -194,8 +214,9 @@ bool isPtrConversion(const FunctionDecl *F) {
194214
// FIXME: check # of params == 1
195215
const auto FunctionName = safeGetName(F);
196216
if (FunctionName == "getPtr" || FunctionName == "WeakPtr" ||
197-
FunctionName == "dynamicDowncast"
198-
|| FunctionName == "downcast" || FunctionName == "bitwise_cast")
217+
FunctionName == "dynamicDowncast" || FunctionName == "downcast" ||
218+
FunctionName == "checkedDowncast" ||
219+
FunctionName == "uncheckedDowncast" || FunctionName == "bitwise_cast")
199220
return true;
200221

201222
return false;

clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@ std::optional<bool> isUncountedPtr(const clang::Type* T);
5050
/// false if not.
5151
bool isCtorOfRefCounted(const clang::FunctionDecl *F);
5252

53+
/// \returns true if \p F returns a ref-counted object, false if not.
54+
bool isReturnValueRefCounted(const clang::FunctionDecl *F);
55+
5356
/// \returns true if \p M is getter of a ref-counted class, false if not.
5457
std::optional<bool> isGetterOfRefCounted(const clang::CXXMethodDecl* Method);
5558

0 commit comments

Comments
 (0)