Skip to content

Commit c11d5c0

Browse files
committed
[AutoBump] Merge with e240261 (Jan 17)
2 parents ef04755 + e240261 commit c11d5c0

File tree

294 files changed

+8272
-4312
lines changed

Some content is hidden

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

294 files changed

+8272
-4312
lines changed

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

Lines changed: 64 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,11 @@
99
#include "RawStringLiteralCheck.h"
1010
#include "clang/AST/ASTContext.h"
1111
#include "clang/ASTMatchers/ASTMatchFinder.h"
12+
#include "clang/Basic/LangOptions.h"
13+
#include "clang/Basic/SourceManager.h"
1214
#include "clang/Lex/Lexer.h"
15+
#include "llvm/ADT/StringRef.h"
16+
#include <optional>
1317

1418
using namespace clang::ast_matchers;
1519

@@ -66,20 +70,6 @@ bool containsDelimiter(StringRef Bytes, const std::string &Delimiter) {
6670
: (")" + Delimiter + R"(")")) != StringRef::npos;
6771
}
6872

69-
std::string asRawStringLiteral(const StringLiteral *Literal,
70-
const std::string &DelimiterStem) {
71-
const StringRef Bytes = Literal->getBytes();
72-
std::string Delimiter;
73-
for (int I = 0; containsDelimiter(Bytes, Delimiter); ++I) {
74-
Delimiter = (I == 0) ? DelimiterStem : DelimiterStem + std::to_string(I);
75-
}
76-
77-
if (Delimiter.empty())
78-
return (R"(R"()" + Bytes + R"lit()")lit").str();
79-
80-
return (R"(R")" + Delimiter + "(" + Bytes + ")" + Delimiter + R"(")").str();
81-
}
82-
8373
} // namespace
8474

8575
RawStringLiteralCheck::RawStringLiteralCheck(StringRef Name,
@@ -119,30 +109,73 @@ void RawStringLiteralCheck::registerMatchers(MatchFinder *Finder) {
119109
stringLiteral(unless(hasParent(predefinedExpr()))).bind("lit"), this);
120110
}
121111

112+
static std::optional<StringRef>
113+
createUserDefinedSuffix(const StringLiteral *Literal, const SourceManager &SM,
114+
const LangOptions &LangOpts) {
115+
const CharSourceRange TokenRange =
116+
CharSourceRange::getTokenRange(Literal->getSourceRange());
117+
Token T;
118+
if (Lexer::getRawToken(Literal->getBeginLoc(), T, SM, LangOpts))
119+
return std::nullopt;
120+
const CharSourceRange CharRange =
121+
Lexer::makeFileCharRange(TokenRange, SM, LangOpts);
122+
if (T.hasUDSuffix()) {
123+
StringRef Text = Lexer::getSourceText(CharRange, SM, LangOpts);
124+
const size_t UDSuffixPos = Text.find_last_of('"');
125+
if (UDSuffixPos == StringRef::npos)
126+
return std::nullopt;
127+
return Text.slice(UDSuffixPos + 1, Text.size());
128+
}
129+
return std::nullopt;
130+
}
131+
132+
static std::string createRawStringLiteral(const StringLiteral *Literal,
133+
const std::string &DelimiterStem,
134+
const SourceManager &SM,
135+
const LangOptions &LangOpts) {
136+
const StringRef Bytes = Literal->getBytes();
137+
std::string Delimiter;
138+
for (int I = 0; containsDelimiter(Bytes, Delimiter); ++I) {
139+
Delimiter = (I == 0) ? DelimiterStem : DelimiterStem + std::to_string(I);
140+
}
141+
142+
std::optional<StringRef> UserDefinedSuffix =
143+
createUserDefinedSuffix(Literal, SM, LangOpts);
144+
145+
if (Delimiter.empty())
146+
return (R"(R"()" + Bytes + R"lit()")lit" + UserDefinedSuffix.value_or(""))
147+
.str();
148+
149+
return (R"(R")" + Delimiter + "(" + Bytes + ")" + Delimiter + R"(")" +
150+
UserDefinedSuffix.value_or(""))
151+
.str();
152+
}
153+
154+
static bool compareStringLength(StringRef Replacement,
155+
const StringLiteral *Literal,
156+
const SourceManager &SM,
157+
const LangOptions &LangOpts) {
158+
return Replacement.size() <=
159+
Lexer::MeasureTokenLength(Literal->getBeginLoc(), SM, LangOpts);
160+
}
161+
122162
void RawStringLiteralCheck::check(const MatchFinder::MatchResult &Result) {
123163
const auto *Literal = Result.Nodes.getNodeAs<StringLiteral>("lit");
124164
if (Literal->getBeginLoc().isMacroID())
125165
return;
126-
166+
const SourceManager &SM = *Result.SourceManager;
167+
const LangOptions &LangOpts = getLangOpts();
127168
if (containsEscapedCharacters(Result, Literal, DisallowedChars)) {
128-
std::string Replacement = asRawStringLiteral(Literal, DelimiterStem);
169+
const std::string Replacement =
170+
createRawStringLiteral(Literal, DelimiterStem, SM, LangOpts);
129171
if (ReplaceShorterLiterals ||
130-
Replacement.length() <=
131-
Lexer::MeasureTokenLength(Literal->getBeginLoc(),
132-
*Result.SourceManager, getLangOpts()))
133-
replaceWithRawStringLiteral(Result, Literal, Replacement);
172+
compareStringLength(Replacement, Literal, SM, LangOpts)) {
173+
diag(Literal->getBeginLoc(),
174+
"escaped string literal can be written as a raw string literal")
175+
<< FixItHint::CreateReplacement(Literal->getSourceRange(),
176+
Replacement);
177+
}
134178
}
135179
}
136180

137-
void RawStringLiteralCheck::replaceWithRawStringLiteral(
138-
const MatchFinder::MatchResult &Result, const StringLiteral *Literal,
139-
StringRef Replacement) {
140-
CharSourceRange CharRange = Lexer::makeFileCharRange(
141-
CharSourceRange::getTokenRange(Literal->getSourceRange()),
142-
*Result.SourceManager, getLangOpts());
143-
diag(Literal->getBeginLoc(),
144-
"escaped string literal can be written as a raw string literal")
145-
<< FixItHint::CreateReplacement(CharRange, Replacement);
146-
}
147-
148181
} // namespace clang::tidy::modernize

clang-tools-extra/clang-tidy/modernize/RawStringLiteralCheck.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,6 @@ class RawStringLiteralCheck : public ClangTidyCheck {
3333
void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
3434

3535
private:
36-
void replaceWithRawStringLiteral(
37-
const ast_matchers::MatchFinder::MatchResult &Result,
38-
const StringLiteral *Literal, StringRef Replacement);
39-
4036
std::string DelimiterStem;
4137
CharsBitSet DisallowedChars;
4238
const bool ReplaceShorterLiterals;

clang-tools-extra/clangd/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,6 @@ add_clang_library(clangDaemon STATIC
9191
GlobalCompilationDatabase.cpp
9292
Headers.cpp
9393
HeaderSourceSwitch.cpp
94-
HeuristicResolver.cpp
9594
Hover.cpp
9695
IncludeCleaner.cpp
9796
IncludeFixer.cpp

clang-tools-extra/clangd/FindTarget.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88

99
#include "FindTarget.h"
1010
#include "AST.h"
11-
#include "HeuristicResolver.h"
1211
#include "support/Logger.h"
1312
#include "clang/AST/ASTConcept.h"
1413
#include "clang/AST/ASTTypeTraits.h"
@@ -35,6 +34,7 @@
3534
#include "clang/Basic/SourceLocation.h"
3635
#include "clang/Basic/SourceManager.h"
3736
#include "clang/Basic/Specifiers.h"
37+
#include "clang/Sema/HeuristicResolver.h"
3838
#include "llvm/ADT/STLExtras.h"
3939
#include "llvm/ADT/SmallVector.h"
4040
#include "llvm/ADT/StringExtras.h"

clang-tools-extra/clangd/FindTarget.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,11 @@
3333
#include <bitset>
3434

3535
namespace clang {
36-
namespace clangd {
36+
3737
class HeuristicResolver;
3838

39+
namespace clangd {
40+
3941
/// Describes the link between an AST node and a Decl it refers to.
4042
enum class DeclRelation : unsigned;
4143
/// A bitfield of DeclRelations.

clang-tools-extra/clangd/InlayHints.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
#include "../clang-tidy/utils/DesignatedInitializers.h"
1010
#include "AST.h"
1111
#include "Config.h"
12-
#include "HeuristicResolver.h"
1312
#include "ParsedAST.h"
1413
#include "Protocol.h"
1514
#include "SourceCode.h"
@@ -27,6 +26,7 @@
2726
#include "clang/Basic/OperatorKinds.h"
2827
#include "clang/Basic/SourceLocation.h"
2928
#include "clang/Basic/SourceManager.h"
29+
#include "clang/Sema/HeuristicResolver.h"
3030
#include "llvm/ADT/DenseSet.h"
3131
#include "llvm/ADT/STLExtras.h"
3232
#include "llvm/ADT/SmallVector.h"

clang-tools-extra/clangd/ParsedAST.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
#include "Feature.h"
2121
#include "FeatureModule.h"
2222
#include "Headers.h"
23-
#include "HeuristicResolver.h"
2423
#include "IncludeCleaner.h"
2524
#include "IncludeFixer.h"
2625
#include "Preamble.h"
@@ -53,6 +52,7 @@
5352
#include "clang/Lex/Lexer.h"
5453
#include "clang/Lex/PPCallbacks.h"
5554
#include "clang/Lex/Preprocessor.h"
55+
#include "clang/Sema/HeuristicResolver.h"
5656
#include "clang/Serialization/ASTWriter.h"
5757
#include "clang/Tooling/CompilationDatabase.h"
5858
#include "clang/Tooling/Core/Diagnostic.h"

clang-tools-extra/clangd/ParsedAST.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,9 @@
3838
#include <vector>
3939

4040
namespace clang {
41+
class HeuristicResolver;
4142
class Sema;
4243
namespace clangd {
43-
class HeuristicResolver;
4444

4545
/// Stores and provides access to parsed AST.
4646
class ParsedAST {

clang-tools-extra/clangd/SemanticHighlighting.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
#include "SemanticHighlighting.h"
1010
#include "Config.h"
1111
#include "FindTarget.h"
12-
#include "HeuristicResolver.h"
1312
#include "ParsedAST.h"
1413
#include "Protocol.h"
1514
#include "SourceCode.h"
@@ -27,6 +26,7 @@
2726
#include "clang/Basic/LangOptions.h"
2827
#include "clang/Basic/SourceLocation.h"
2928
#include "clang/Basic/SourceManager.h"
29+
#include "clang/Sema/HeuristicResolver.h"
3030
#include "clang/Tooling/Syntax/Tokens.h"
3131
#include "llvm/ADT/STLExtras.h"
3232
#include "llvm/ADT/StringRef.h"

clang-tools-extra/clangd/XRefs.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
#include "FindSymbols.h"
1111
#include "FindTarget.h"
1212
#include "Headers.h"
13-
#include "HeuristicResolver.h"
1413
#include "IncludeCleaner.h"
1514
#include "ParsedAST.h"
1615
#include "Protocol.h"
@@ -53,6 +52,7 @@
5352
#include "clang/Index/IndexingOptions.h"
5453
#include "clang/Index/USRGeneration.h"
5554
#include "clang/Lex/Lexer.h"
55+
#include "clang/Sema/HeuristicResolver.h"
5656
#include "clang/Tooling/Syntax/Tokens.h"
5757
#include "llvm/ADT/ArrayRef.h"
5858
#include "llvm/ADT/DenseMap.h"

clang-tools-extra/clangd/unittests/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,6 @@ add_unittest(ClangdUnitTests ClangdTests
6464
GlobalCompilationDatabaseTests.cpp
6565
HeadersTests.cpp
6666
HeaderSourceSwitchTests.cpp
67-
HeuristicResolverTests.cpp
6867
HoverTests.cpp
6968
IncludeCleanerTests.cpp
7069
IndexActionTests.cpp

clang-tools-extra/docs/ReleaseNotes.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,10 @@ Changes in existing checks
321321
a false positive when only an implicit conversion happened inside an
322322
initializer list.
323323

324+
- Improved :doc:`modernize-raw-string-literal
325+
<clang-tidy/checks/modernize/raw-string-literal>` check to fix incorrect
326+
fix-it when the string contains a user-defined suffix.
327+
324328
- Improved :doc:`modernize-use-designated-initializers
325329
<clang-tidy/checks/modernize/use-designated-initializers>` check to fix a
326330
crash when a class is declared but not defined.

clang-tools-extra/test/clang-tidy/checkers/modernize/raw-string-literal.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,3 +129,16 @@ void callFn() {
129129
// CHECK-MESSAGES: :[[@LINE-1]]:14: warning: {{.*}} can be written as a raw string literal
130130
// CHECK-FIXES: {{^}} fn<double>(R"(foo\bar)");{{$}}
131131
}
132+
133+
namespace std {
134+
using size_t = decltype(sizeof(0));
135+
namespace ud {
136+
int operator""_abc(const char *str, std::size_t len);
137+
} // namespace ud
138+
} // namespace std
139+
namespace gh97243 {
140+
using namespace std::ud;
141+
auto UserDefinedLiteral = "foo\\bar"_abc;
142+
// CHECK-MESSAGES: :[[@LINE-1]]:27: warning: {{.*}} can be written as a raw string literal
143+
// CHECK-FIXES: {{^}}auto UserDefinedLiteral = R"(foo\bar)"_abc;
144+
} // namespace gh97243

clang/cmake/caches/Fuchsia-stage2.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,7 @@ if(FUCHSIA_SDK)
300300
set(LLVM_RUNTIME_MULTILIB_hwasan+noexcept_TARGETS "aarch64-unknown-fuchsia;riscv64-unknown-fuchsia" CACHE STRING "")
301301
endif()
302302

303-
foreach(target armv6m-none-eabi;armv7m-none-eabi;armv8m.main-none-eabi;armv8.1m.main-none-eabi;aarch64-none-elf)
303+
foreach(target armv6m-none-eabi;armv7m-none-eabi;armv7em-none-eabi;armv8m.main-none-eabi;armv8.1m.main-none-eabi;aarch64-none-elf)
304304
list(APPEND BUILTIN_TARGETS "${target}")
305305
set(BUILTINS_${target}_CMAKE_SYSTEM_NAME Generic CACHE STRING "")
306306
set(BUILTINS_${target}_CMAKE_SYSTEM_PROCESSOR arm CACHE STRING "")

clang/include/clang/AST/ASTContext.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1726,6 +1726,13 @@ class ASTContext : public RefCountedBase<ASTContext> {
17261726

17271727
QualType getEnumType(const EnumDecl *Decl) const;
17281728

1729+
/// Compute BestType and BestPromotionType for an enum based on the highest
1730+
/// number of negative and positive bits of its elements.
1731+
/// Returns true if enum width is too large.
1732+
bool computeBestEnumTypes(bool IsPacked, unsigned NumNegativeBits,
1733+
unsigned NumPositiveBits, QualType &BestType,
1734+
QualType &BestPromotionType);
1735+
17291736
QualType
17301737
getUnresolvedUsingType(const UnresolvedUsingTypenameDecl *Decl) const;
17311738

clang/include/clang/AST/Type.h

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8841,13 +8841,16 @@ void FixedPointValueToString(SmallVectorImpl<char> &Str, llvm::APSInt Val,
88418841
unsigned Scale);
88428842

88438843
inline FunctionEffectsRef FunctionEffectsRef::get(QualType QT) {
8844+
const Type *TypePtr = QT.getTypePtr();
88448845
while (true) {
8845-
QualType Pointee = QT->getPointeeType();
8846-
if (Pointee.isNull())
8846+
if (QualType Pointee = TypePtr->getPointeeType(); !Pointee.isNull())
8847+
TypePtr = Pointee.getTypePtr();
8848+
else if (TypePtr->isArrayType())
8849+
TypePtr = TypePtr->getBaseElementTypeUnsafe();
8850+
else
88478851
break;
8848-
QT = Pointee;
88498852
}
8850-
if (const auto *FPT = QT->getAs<FunctionProtoType>())
8853+
if (const auto *FPT = TypePtr->getAs<FunctionProtoType>())
88518854
return FPT->getFunctionEffects();
88528855
return {};
88538856
}

clang/include/clang/AST/TypeLoc.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -397,6 +397,7 @@ class ConcreteTypeLoc : public Base {
397397
unsigned extraAlign = asDerived()->getExtraLocalDataAlignment();
398398
size = llvm::alignTo(size, extraAlign);
399399
size += asDerived()->getExtraLocalDataSize();
400+
size = llvm::alignTo(size, asDerived()->getLocalDataAlignment());
400401
return size;
401402
}
402403

clang/include/clang/Basic/BuiltinsSPIRV.td

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,9 @@ def SPIRVDistance : Builtin {
1313
let Attributes = [NoThrow, Const];
1414
let Prototype = "void(...)";
1515
}
16+
17+
def SPIRVLength : Builtin {
18+
let Spellings = ["__builtin_spirv_length"];
19+
let Attributes = [NoThrow, Const];
20+
let Prototype = "void(...)";
21+
}

clang/include/clang/Basic/BuiltinsX86_64.td

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -295,8 +295,8 @@ let Features = "amx-complex,amx-transpose", Attributes = [NoThrow] in {
295295

296296
let Features = "amx-avx512,avx10.2-512", Attributes = [NoThrow] in {
297297
def tcvtrowd2ps_internal : X86Builtin<"_Vector<16, float>(unsigned short, unsigned short, _Vector<256, int>, unsigned int)">;
298-
def tcvtrowps2pbf16h_internal : X86Builtin<"_Vector<32, __bf16>(unsigned short, unsigned short, _Vector<256, int>, unsigned int)">;
299-
def tcvtrowps2pbf16l_internal : X86Builtin<"_Vector<32, __bf16>(unsigned short, unsigned short, _Vector<256, int>, unsigned int)">;
298+
def tcvtrowps2bf16h_internal : X86Builtin<"_Vector<32, __bf16>(unsigned short, unsigned short, _Vector<256, int>, unsigned int)">;
299+
def tcvtrowps2bf16l_internal : X86Builtin<"_Vector<32, __bf16>(unsigned short, unsigned short, _Vector<256, int>, unsigned int)">;
300300
def tcvtrowps2phh_internal : X86Builtin<"_Vector<32, _Float16>(unsigned short, unsigned short, _Vector<256, int>, unsigned int)">;
301301
def tcvtrowps2phl_internal : X86Builtin<"_Vector<32, _Float16>(unsigned short, unsigned short, _Vector<256, int>, unsigned int)">;
302302
def tilemovrow_internal : X86Builtin<"_Vector<16, int>(unsigned short, unsigned short, _Vector<256, int>, unsigned int)">;
@@ -387,8 +387,8 @@ let Features = "amx-complex,amx-transpose", Attributes = [NoThrow] in {
387387

388388
let Features = "amx-avx512,avx10.2-512", Attributes = [NoThrow] in {
389389
def tcvtrowd2ps : X86Builtin<"_Vector<16, float>(_Constant unsigned char, unsigned int)">;
390-
def tcvtrowps2pbf16h : X86Builtin<"_Vector<32, __bf16>(_Constant unsigned char, unsigned int)">;
391-
def tcvtrowps2pbf16l : X86Builtin<"_Vector<32, __bf16>(_Constant unsigned char, unsigned int)">;
390+
def tcvtrowps2bf16h : X86Builtin<"_Vector<32, __bf16>(_Constant unsigned char, unsigned int)">;
391+
def tcvtrowps2bf16l : X86Builtin<"_Vector<32, __bf16>(_Constant unsigned char, unsigned int)">;
392392
def tcvtrowps2phh : X86Builtin<"_Vector<32, _Float16>(_Constant unsigned char, unsigned int)">;
393393
def tcvtrowps2phl : X86Builtin<"_Vector<32, _Float16>(_Constant unsigned char, unsigned int)">;
394394
def tilemovrow : X86Builtin<"_Vector<16, int>(_Constant unsigned char, unsigned int)">;

clang-tools-extra/clangd/HeuristicResolver.h renamed to clang/include/clang/Sema/HeuristicResolver.h

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
//
77
//===----------------------------------------------------------------------===//
88

9-
#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANGD_HEURISTICRESOLVER_H
10-
#define LLVM_CLANG_TOOLS_EXTRA_CLANGD_HEURISTICRESOLVER_H
9+
#ifndef LLVM_CLANG_SEMA_HEURISTICRESOLVER_H
10+
#define LLVM_CLANG_SEMA_HEURISTICRESOLVER_H
1111

1212
#include "clang/AST/Decl.h"
1313
#include <vector>
@@ -24,8 +24,6 @@ class NamedDecl;
2424
class Type;
2525
class UnresolvedUsingValueDecl;
2626

27-
namespace clangd {
28-
2927
// This class handles heuristic resolution of declarations and types in template
3028
// code.
3129
//
@@ -80,7 +78,6 @@ class HeuristicResolver {
8078
ASTContext &Ctx;
8179
};
8280

83-
} // namespace clangd
8481
} // namespace clang
8582

8683
#endif

0 commit comments

Comments
 (0)