Skip to content

Commit 6c7fcc4

Browse files
authored
Merge branch 'main' into loop-vectorize/evl-exit-cond-avlnext-zero
2 parents 13be3c8 + aaae6ac commit 6c7fcc4

File tree

347 files changed

+20395
-1025
lines changed

Some content is hidden

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

347 files changed

+20395
-1025
lines changed

clang-tools-extra/clangd/ModulesBuilder.cpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,21 @@
1414
#include "clang/Serialization/ASTReader.h"
1515
#include "clang/Serialization/ModuleCache.h"
1616
#include "llvm/ADT/ScopeExit.h"
17+
#include "llvm/Support/CommandLine.h"
18+
1719
#include <queue>
1820

1921
namespace clang {
2022
namespace clangd {
2123

2224
namespace {
2325

26+
llvm::cl::opt<bool> DebugModulesBuilder(
27+
"debug-modules-builder",
28+
llvm::cl::desc("Don't remove clangd's built module files for debugging. "
29+
"Remember to remove them later after debugging."),
30+
llvm::cl::init(false));
31+
2432
// Create a path to store module files. Generally it should be:
2533
//
2634
// {TEMP_DIRS}/clangd/module_files/{hashed-file-name}-%%-%%-%%-%%-%%-%%/.
@@ -122,7 +130,7 @@ struct ModuleFile {
122130
}
123131

124132
~ModuleFile() {
125-
if (!ModuleFilePath.empty())
133+
if (!ModuleFilePath.empty() && !DebugModulesBuilder)
126134
llvm::sys::fs::remove(ModuleFilePath);
127135
}
128136

@@ -315,7 +323,7 @@ buildModuleFile(llvm::StringRef ModuleName, PathRef ModuleUnitFileName,
315323
Cmds += Arg;
316324
}
317325

318-
clangd::vlog("Failed to compile {0} with command: {1}.", ModuleUnitFileName,
326+
clangd::vlog("Failed to compile {0} with command: {1}", ModuleUnitFileName,
319327
Cmds);
320328

321329
std::string BuiltModuleFilesStr = BuiltModuleFiles.getAsString();

clang/include/clang/AST/TemplateName.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -335,17 +335,17 @@ class TemplateName {
335335
/// structure, if any.
336336
QualifiedTemplateName *getAsQualifiedTemplateName() const;
337337

338-
/// Retrieve the underlying qualified template name,
339-
/// looking through underlying nodes.
340-
QualifiedTemplateName *getAsAdjustedQualifiedTemplateName() const;
341-
342338
/// Retrieve the underlying dependent template name
343339
/// structure, if any.
344340
DependentTemplateName *getAsDependentTemplateName() const;
345341

346-
// Retrieve the qualifier stored in either a underlying DependentTemplateName
347-
// or QualifiedTemplateName.
348-
NestedNameSpecifier getQualifier() const;
342+
// Retrieve the qualifier and template keyword stored in either a underlying
343+
// DependentTemplateName or QualifiedTemplateName.
344+
std::tuple<NestedNameSpecifier, bool> getQualifierAndTemplateKeyword() const;
345+
346+
NestedNameSpecifier getQualifier() const {
347+
return std::get<0>(getQualifierAndTemplateKeyword());
348+
}
349349

350350
/// Retrieve the using shadow declaration through which the underlying
351351
/// template declaration is introduced, if any.

clang/include/clang/AST/TypeLoc.h

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1872,11 +1872,10 @@ class TemplateSpecializationTypeLoc :
18721872
if (!getLocalData()->QualifierData)
18731873
return NestedNameSpecifierLoc();
18741874

1875-
auto *QTN =
1876-
getTypePtr()->getTemplateName().getAsAdjustedQualifiedTemplateName();
1877-
assert(QTN && "missing qualification");
1878-
return NestedNameSpecifierLoc(QTN->getQualifier(),
1879-
getLocalData()->QualifierData);
1875+
NestedNameSpecifier Qualifier =
1876+
getTypePtr()->getTemplateName().getQualifier();
1877+
assert(Qualifier && "missing qualification");
1878+
return NestedNameSpecifierLoc(Qualifier, getLocalData()->QualifierData);
18801879
}
18811880

18821881
SourceLocation getTemplateKeywordLoc() const {
@@ -2503,10 +2502,9 @@ class DeducedTemplateSpecializationTypeLoc
25032502
void *Data = getLocalData()->QualifierData;
25042503
if (!Data)
25052504
return NestedNameSpecifierLoc();
2506-
NestedNameSpecifier Qualifier = getTypePtr()
2507-
->getTemplateName()
2508-
.getAsAdjustedQualifiedTemplateName()
2509-
->getQualifier();
2505+
NestedNameSpecifier Qualifier =
2506+
getTypePtr()->getTemplateName().getQualifier();
2507+
assert(Qualifier && "missing qualification");
25102508
return NestedNameSpecifierLoc(Qualifier, Data);
25112509
}
25122510

@@ -2521,10 +2519,7 @@ class DeducedTemplateSpecializationTypeLoc
25212519
}
25222520

25232521
assert(QualifierLoc.getNestedNameSpecifier() ==
2524-
getTypePtr()
2525-
->getTemplateName()
2526-
.getAsAdjustedQualifiedTemplateName()
2527-
->getQualifier() &&
2522+
getTypePtr()->getTemplateName().getQualifier() &&
25282523
"Inconsistent nested-name-specifier pointer");
25292524
getLocalData()->QualifierData = QualifierLoc.getOpaqueData();
25302525
}

clang/include/clang/Basic/CodeGenOptions.def

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ ENUM_CODEGENOPT(FramePointer, FramePointerKind, 2, FramePointerKind::None, Benig
5858

5959
ENUM_CODEGENOPT(ExceptionHandling, ExceptionHandlingKind, 3, ExceptionHandlingKind::None, NotCompatible)
6060

61-
CODEGENOPT(ClearASTBeforeBackend , 1, 0, Benign) ///< Free the AST before running backend code generation. Only works with -disable-free.
61+
CODEGENOPT(ClearASTBeforeBackend , 1, 0, Benign) ///< Free the AST before running backend code generation.
6262
CODEGENOPT(DisableFree , 1, 0, Benign) ///< Don't free memory.
6363
CODEGENOPT(DiscardValueNames , 1, 0, Benign) ///< Discard Value Names from the IR (LLVMContext flag)
6464
CODEGENOPT(DisableLLVMPasses , 1, 0, Benign) ///< Don't run any LLVM IR passes to get

clang/include/clang/Interpreter/Interpreter.h

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ class ThreadSafeContext;
3737
namespace clang {
3838

3939
class CompilerInstance;
40-
class CodeGenerator;
4140
class CXXRecordDecl;
4241
class Decl;
4342
class IncrementalExecutor;
@@ -110,10 +109,6 @@ class Interpreter {
110109
// printing happens, it's in an invalid state.
111110
Value LastValue;
112111

113-
/// When CodeGen is created the first llvm::Module gets cached in many places
114-
/// and we must keep it alive.
115-
std::unique_ptr<llvm::Module> CachedInCodeGenModule;
116-
117112
/// Compiler instance performing the incremental compilation.
118113
std::unique_ptr<CompilerInstance> CI;
119114

@@ -175,15 +170,9 @@ class Interpreter {
175170
llvm::Expected<llvm::orc::ExecutorAddr>
176171
getSymbolAddressFromLinkerName(llvm::StringRef LinkerName) const;
177172

178-
std::unique_ptr<llvm::Module> GenModule(IncrementalAction *Action = nullptr);
179-
PartialTranslationUnit &RegisterPTU(TranslationUnitDecl *TU,
180-
std::unique_ptr<llvm::Module> M = {},
181-
IncrementalAction *Action = nullptr);
182-
183173
private:
184174
size_t getEffectivePTUSize() const;
185175
void markUserCodeStart();
186-
llvm::Expected<Expr *> ExtractValueFromExpr(Expr *E);
187176

188177
// A cache for the compiled destructors used to for de-allocation of managed
189178
// clang::Values.
@@ -206,11 +195,6 @@ class Interpreter {
206195
// This function forces emission of the needed dtor.
207196
llvm::Expected<llvm::orc::ExecutorAddr>
208197
CompileDtorCall(CXXRecordDecl *CXXRD) const;
209-
210-
/// @}
211-
/// @name Code generation
212-
/// @{
213-
CodeGenerator *getCodeGen(IncrementalAction *Action = nullptr) const;
214198
};
215199
} // namespace clang
216200

clang/lib/AST/ASTContext.cpp

Lines changed: 26 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -5474,18 +5474,15 @@ TagType *ASTContext::getTagTypeInternal(ElaboratedTypeKeyword Keyword,
54745474
return T;
54755475
}
54765476

5477-
static bool getNonInjectedClassName(const TagDecl *&TD) {
5477+
static const TagDecl *getNonInjectedClassName(const TagDecl *TD) {
54785478
if (const auto *RD = dyn_cast<CXXRecordDecl>(TD);
5479-
RD && RD->isInjectedClassName()) {
5480-
TD = cast<TagDecl>(RD->getDeclContext());
5481-
return true;
5482-
}
5483-
return false;
5479+
RD && RD->isInjectedClassName())
5480+
return cast<TagDecl>(RD->getDeclContext());
5481+
return TD;
54845482
}
54855483

54865484
CanQualType ASTContext::getCanonicalTagType(const TagDecl *TD) const {
5487-
::getNonInjectedClassName(TD);
5488-
TD = TD->getCanonicalDecl();
5485+
TD = ::getNonInjectedClassName(TD)->getCanonicalDecl();
54895486
if (TD->TypeForDecl)
54905487
return TD->TypeForDecl->getCanonicalTypeUnqualified();
54915488

@@ -5501,40 +5498,42 @@ CanQualType ASTContext::getCanonicalTagType(const TagDecl *TD) const {
55015498
QualType ASTContext::getTagType(ElaboratedTypeKeyword Keyword,
55025499
NestedNameSpecifier Qualifier,
55035500
const TagDecl *TD, bool OwnsTag) const {
5501+
5502+
const TagDecl *NonInjectedTD = ::getNonInjectedClassName(TD);
5503+
bool IsInjected = TD != NonInjectedTD;
5504+
55045505
ElaboratedTypeKeyword PreferredKeyword =
5505-
getLangOpts().CPlusPlus
5506-
? ElaboratedTypeKeyword::None
5507-
: KeywordHelpers::getKeywordForTagTypeKind(TD->getTagKind());
5506+
getLangOpts().CPlusPlus ? ElaboratedTypeKeyword::None
5507+
: KeywordHelpers::getKeywordForTagTypeKind(
5508+
NonInjectedTD->getTagKind());
55085509

55095510
if (Keyword == PreferredKeyword && !Qualifier && !OwnsTag) {
55105511
if (const Type *T = TD->TypeForDecl; T && !T->isCanonicalUnqualified())
55115512
return QualType(T, 0);
55125513

5513-
bool IsInjected = ::getNonInjectedClassName(TD);
5514-
const Type *CanonicalType = getCanonicalTagType(TD).getTypePtr();
5514+
const Type *CanonicalType = getCanonicalTagType(NonInjectedTD).getTypePtr();
55155515
const Type *T =
55165516
getTagTypeInternal(Keyword,
5517-
/*Qualifier=*/std::nullopt, TD,
5517+
/*Qualifier=*/std::nullopt, NonInjectedTD,
55185518
/*OwnsTag=*/false, IsInjected, CanonicalType,
55195519
/*WithFoldingSetNode=*/false);
55205520
TD->TypeForDecl = T;
55215521
return QualType(T, 0);
55225522
}
55235523

5524-
bool IsInjected = ::getNonInjectedClassName(TD);
5525-
55265524
llvm::FoldingSetNodeID ID;
5527-
TagTypeFoldingSetPlaceholder::Profile(ID, Keyword, Qualifier, TD, OwnsTag,
5528-
IsInjected);
5525+
TagTypeFoldingSetPlaceholder::Profile(ID, Keyword, Qualifier, NonInjectedTD,
5526+
OwnsTag, IsInjected);
55295527

55305528
void *InsertPos = nullptr;
55315529
if (TagTypeFoldingSetPlaceholder *T =
55325530
TagTypes.FindNodeOrInsertPos(ID, InsertPos))
55335531
return QualType(T->getTagType(), 0);
55345532

5535-
const Type *CanonicalType = getCanonicalTagType(TD).getTypePtr();
5536-
TagType *T = getTagTypeInternal(Keyword, Qualifier, TD, OwnsTag, IsInjected,
5537-
CanonicalType, /*WithFoldingSetNode=*/true);
5533+
const Type *CanonicalType = getCanonicalTagType(NonInjectedTD).getTypePtr();
5534+
TagType *T =
5535+
getTagTypeInternal(Keyword, Qualifier, NonInjectedTD, OwnsTag, IsInjected,
5536+
CanonicalType, /*WithFoldingSetNode=*/true);
55385537
TagTypes.InsertNode(TagTypeFoldingSetPlaceholder::fromTagType(T), InsertPos);
55395538
return QualType(T, 0);
55405539
}
@@ -10447,6 +10446,12 @@ TemplateName ASTContext::getQualifiedTemplateName(NestedNameSpecifier Qualifier,
1044710446
assert(Template.getKind() == TemplateName::Template ||
1044810447
Template.getKind() == TemplateName::UsingTemplate);
1044910448

10449+
if (Template.getAsTemplateDecl()->getKind() == Decl::TemplateTemplateParm) {
10450+
assert(!Qualifier && "unexpected qualified template template parameter");
10451+
assert(TemplateKeyword == false);
10452+
return Template;
10453+
}
10454+
1045010455
// FIXME: Canonicalization?
1045110456
llvm::FoldingSetNodeID ID;
1045210457
QualifiedTemplateName::Profile(ID, Qualifier, TemplateKeyword, Template);

clang/lib/AST/ByteCode/Compiler.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5230,6 +5230,12 @@ bool Compiler<Emitter>::VisitCallExpr(const CallExpr *E) {
52305230
const Function *Func = getFunction(FuncDecl);
52315231
if (!Func)
52325232
return false;
5233+
5234+
// In error cases, the function may be called with fewer arguments than
5235+
// parameters.
5236+
if (E->getNumArgs() < Func->getNumWrittenParams())
5237+
return false;
5238+
52335239
assert(HasRVO == Func->hasRVO());
52345240

52355241
bool HasQualifier = false;

clang/lib/AST/ByteCode/EvaluationResult.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -178,8 +178,8 @@ bool EvaluationResult::checkFullyInitialized(InterpState &S,
178178
static void collectBlocks(const Pointer &Ptr,
179179
llvm::SetVector<const Block *> &Blocks) {
180180
auto isUsefulPtr = [](const Pointer &P) -> bool {
181-
return P.isLive() && !P.isZero() && !P.isDummy() && P.isDereferencable() &&
182-
!P.isUnknownSizeArray() && !P.isOnePastEnd();
181+
return P.isLive() && P.isBlockPointer() && !P.isZero() && !P.isDummy() &&
182+
P.isDereferencable() && !P.isUnknownSizeArray() && !P.isOnePastEnd();
183183
};
184184

185185
if (!isUsefulPtr(Ptr))

clang/lib/AST/ByteCode/Interp.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2117,8 +2117,8 @@ bool DiagTypeid(InterpState &S, CodePtr OpPC) {
21172117

21182118
bool arePotentiallyOverlappingStringLiterals(const Pointer &LHS,
21192119
const Pointer &RHS) {
2120-
unsigned LHSOffset = LHS.getIndex();
2121-
unsigned RHSOffset = RHS.getIndex();
2120+
unsigned LHSOffset = LHS.isOnePastEnd() ? LHS.getNumElems() : LHS.getIndex();
2121+
unsigned RHSOffset = RHS.isOnePastEnd() ? RHS.getNumElems() : RHS.getIndex();
21222122
unsigned LHSLength = (LHS.getNumElems() - 1) * LHS.elemSize();
21232123
unsigned RHSLength = (RHS.getNumElems() - 1) * RHS.elemSize();
21242124

clang/lib/AST/ByteCode/InterpBuiltin.cpp

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2505,12 +2505,8 @@ static bool interp__builtin_is_within_lifetime(InterpState &S, CodePtr OpPC,
25052505
}
25062506

25072507
// Check if we're currently running an initializer.
2508-
for (InterpFrame *Frame = S.Current; Frame; Frame = Frame->Caller) {
2509-
if (const Function *F = Frame->getFunction();
2510-
F && F->isConstructor() && Frame->getThis().block() == Ptr.block()) {
2511-
return Error(2);
2512-
}
2513-
}
2508+
if (llvm::is_contained(S.InitializingBlocks, Ptr.block()))
2509+
return Error(2);
25142510
if (S.EvaluatingDecl && Ptr.getDeclDesc()->asVarDecl() == S.EvaluatingDecl)
25152511
return Error(2);
25162512

0 commit comments

Comments
 (0)