Skip to content

Commit

Permalink
Merge branch 'llvm:main' into llvmgh-101657
Browse files Browse the repository at this point in the history
  • Loading branch information
DhruvSrivastavaX authored Jan 18, 2025
2 parents 49cc9bb + 699f196 commit f428ca6
Show file tree
Hide file tree
Showing 211 changed files with 5,251 additions and 2,345 deletions.
1 change: 0 additions & 1 deletion clang-tools-extra/clang-tidy/misc/UnusedUsingDeclsCheck.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ class UnusedUsingDeclsCheck : public ClangTidyCheck {
std::vector<UsingDeclContext> Contexts;
llvm::SmallPtrSet<const Decl *, 32> UsingTargetDeclsCache;

StringRef RawStringHeaderFileExtensions;
FileExtensionsSet HeaderFileExtensions;
};

Expand Down
1 change: 0 additions & 1 deletion clang-tools-extra/clangd/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,6 @@ add_clang_library(clangDaemon STATIC
GlobalCompilationDatabase.cpp
Headers.cpp
HeaderSourceSwitch.cpp
HeuristicResolver.cpp
Hover.cpp
IncludeCleaner.cpp
IncludeFixer.cpp
Expand Down
2 changes: 1 addition & 1 deletion clang-tools-extra/clangd/FindTarget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

#include "FindTarget.h"
#include "AST.h"
#include "HeuristicResolver.h"
#include "support/Logger.h"
#include "clang/AST/ASTConcept.h"
#include "clang/AST/ASTTypeTraits.h"
Expand All @@ -35,6 +34,7 @@
#include "clang/Basic/SourceLocation.h"
#include "clang/Basic/SourceManager.h"
#include "clang/Basic/Specifiers.h"
#include "clang/Sema/HeuristicResolver.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/StringExtras.h"
Expand Down
4 changes: 3 additions & 1 deletion clang-tools-extra/clangd/FindTarget.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,11 @@
#include <bitset>

namespace clang {
namespace clangd {

class HeuristicResolver;

namespace clangd {

/// Describes the link between an AST node and a Decl it refers to.
enum class DeclRelation : unsigned;
/// A bitfield of DeclRelations.
Expand Down
2 changes: 1 addition & 1 deletion clang-tools-extra/clangd/InlayHints.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
#include "../clang-tidy/utils/DesignatedInitializers.h"
#include "AST.h"
#include "Config.h"
#include "HeuristicResolver.h"
#include "ParsedAST.h"
#include "Protocol.h"
#include "SourceCode.h"
Expand All @@ -27,6 +26,7 @@
#include "clang/Basic/OperatorKinds.h"
#include "clang/Basic/SourceLocation.h"
#include "clang/Basic/SourceManager.h"
#include "clang/Sema/HeuristicResolver.h"
#include "llvm/ADT/DenseSet.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/SmallVector.h"
Expand Down
2 changes: 1 addition & 1 deletion clang-tools-extra/clangd/ParsedAST.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
#include "Feature.h"
#include "FeatureModule.h"
#include "Headers.h"
#include "HeuristicResolver.h"
#include "IncludeCleaner.h"
#include "IncludeFixer.h"
#include "Preamble.h"
Expand Down Expand Up @@ -53,6 +52,7 @@
#include "clang/Lex/Lexer.h"
#include "clang/Lex/PPCallbacks.h"
#include "clang/Lex/Preprocessor.h"
#include "clang/Sema/HeuristicResolver.h"
#include "clang/Serialization/ASTWriter.h"
#include "clang/Tooling/CompilationDatabase.h"
#include "clang/Tooling/Core/Diagnostic.h"
Expand Down
2 changes: 1 addition & 1 deletion clang-tools-extra/clangd/ParsedAST.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@
#include <vector>

namespace clang {
class HeuristicResolver;
class Sema;
namespace clangd {
class HeuristicResolver;

/// Stores and provides access to parsed AST.
class ParsedAST {
Expand Down
2 changes: 1 addition & 1 deletion clang-tools-extra/clangd/SemanticHighlighting.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
#include "SemanticHighlighting.h"
#include "Config.h"
#include "FindTarget.h"
#include "HeuristicResolver.h"
#include "ParsedAST.h"
#include "Protocol.h"
#include "SourceCode.h"
Expand All @@ -27,6 +26,7 @@
#include "clang/Basic/LangOptions.h"
#include "clang/Basic/SourceLocation.h"
#include "clang/Basic/SourceManager.h"
#include "clang/Sema/HeuristicResolver.h"
#include "clang/Tooling/Syntax/Tokens.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/StringRef.h"
Expand Down
2 changes: 1 addition & 1 deletion clang-tools-extra/clangd/XRefs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
#include "FindSymbols.h"
#include "FindTarget.h"
#include "Headers.h"
#include "HeuristicResolver.h"
#include "IncludeCleaner.h"
#include "ParsedAST.h"
#include "Protocol.h"
Expand Down Expand Up @@ -53,6 +52,7 @@
#include "clang/Index/IndexingOptions.h"
#include "clang/Index/USRGeneration.h"
#include "clang/Lex/Lexer.h"
#include "clang/Sema/HeuristicResolver.h"
#include "clang/Tooling/Syntax/Tokens.h"
#include "llvm/ADT/ArrayRef.h"
#include "llvm/ADT/DenseMap.h"
Expand Down
1 change: 0 additions & 1 deletion clang-tools-extra/clangd/unittests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ add_unittest(ClangdUnitTests ClangdTests
GlobalCompilationDatabaseTests.cpp
HeadersTests.cpp
HeaderSourceSwitchTests.cpp
HeuristicResolverTests.cpp
HoverTests.cpp
IncludeCleanerTests.cpp
IndexActionTests.cpp
Expand Down
6 changes: 6 additions & 0 deletions clang/include/clang/Basic/BuiltinsSPIRV.td
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,9 @@ def SPIRVDistance : Builtin {
let Attributes = [NoThrow, Const];
let Prototype = "void(...)";
}

def SPIRVLength : Builtin {
let Spellings = ["__builtin_spirv_length"];
let Attributes = [NoThrow, Const];
let Prototype = "void(...)";
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
//
//===----------------------------------------------------------------------===//

#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANGD_HEURISTICRESOLVER_H
#define LLVM_CLANG_TOOLS_EXTRA_CLANGD_HEURISTICRESOLVER_H
#ifndef LLVM_CLANG_SEMA_HEURISTICRESOLVER_H
#define LLVM_CLANG_SEMA_HEURISTICRESOLVER_H

#include "clang/AST/Decl.h"
#include <vector>
Expand All @@ -24,8 +24,6 @@ class NamedDecl;
class Type;
class UnresolvedUsingValueDecl;

namespace clangd {

// This class handles heuristic resolution of declarations and types in template
// code.
//
Expand Down Expand Up @@ -80,7 +78,6 @@ class HeuristicResolver {
ASTContext &Ctx;
};

} // namespace clangd
} // namespace clang

#endif
93 changes: 56 additions & 37 deletions clang/lib/AST/ByteCode/Compiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6194,48 +6194,67 @@ bool Compiler<Emitter>::visitDeclRef(const ValueDecl *D, const Expr *E) {
return revisit(VD);
}

if (D != InitializingDecl) {
// Try to lazily visit (or emit dummy pointers for) declarations
// we haven't seen yet.
if (Ctx.getLangOpts().CPlusPlus) {
if (const auto *VD = dyn_cast<VarDecl>(D)) {
const auto typeShouldBeVisited = [&](QualType T) -> bool {
if (T.isConstant(Ctx.getASTContext()))
return true;
return T->isReferenceType();
};

// DecompositionDecls are just proxies for us.
if (isa<DecompositionDecl>(VD))
return revisit(VD);
// Avoid infinite recursion.
if (D == InitializingDecl)
return this->emitDummyPtr(D, E);

// Try to lazily visit (or emit dummy pointers for) declarations
// we haven't seen yet.
// For C.
if (!Ctx.getLangOpts().CPlusPlus) {
if (const auto *VD = dyn_cast<VarDecl>(D);
VD && VD->getAnyInitializer() &&
VD->getType().isConstant(Ctx.getASTContext()) && !VD->isWeak())
return revisit(VD);
return this->emitDummyPtr(D, E);
}

if ((VD->hasGlobalStorage() || VD->isStaticDataMember()) &&
typeShouldBeVisited(VD->getType()))
return revisit(VD);
// ... and C++.
const auto *VD = dyn_cast<VarDecl>(D);
if (!VD)
return this->emitDummyPtr(D, E);

// FIXME: The evaluateValue() check here is a little ridiculous, since
// it will ultimately call into Context::evaluateAsInitializer(). In
// other words, we're evaluating the initializer, just to know if we can
// evaluate the initializer.
if (VD->isLocalVarDecl() && typeShouldBeVisited(VD->getType()) &&
VD->getInit() && !VD->getInit()->isValueDependent()) {
const auto typeShouldBeVisited = [&](QualType T) -> bool {
if (T.isConstant(Ctx.getASTContext()))
return true;
return T->isReferenceType();
};

if (VD->evaluateValue())
return revisit(VD);
// DecompositionDecls are just proxies for us.
if (isa<DecompositionDecl>(VD))
return revisit(VD);

if ((VD->hasGlobalStorage() || VD->isStaticDataMember()) &&
typeShouldBeVisited(VD->getType())) {
if (const Expr *Init = VD->getAnyInitializer();
Init && !Init->isValueDependent()) {
// Whether or not the evaluation is successul doesn't really matter
// here -- we will create a global variable in any case, and that
// will have the state of initializer evaluation attached.
APValue V;
SmallVector<PartialDiagnosticAt> Notes;
(void)Init->EvaluateAsInitializer(V, Ctx.getASTContext(), VD, Notes,
true);
return this->visitDeclRef(D, E);
}
return revisit(VD);
}

// FIXME: The evaluateValue() check here is a little ridiculous, since
// it will ultimately call into Context::evaluateAsInitializer(). In
// other words, we're evaluating the initializer, just to know if we can
// evaluate the initializer.
if (VD->isLocalVarDecl() && typeShouldBeVisited(VD->getType()) &&
VD->getInit() && !VD->getInit()->isValueDependent()) {

if (VD->evaluateValue())
return revisit(VD);

if (!D->getType()->isReferenceType())
return this->emitDummyPtr(D, E);
if (!D->getType()->isReferenceType())
return this->emitDummyPtr(D, E);

return this->emitInvalidDeclRef(cast<DeclRefExpr>(E),
/*InitializerFailed=*/true, E);
}
}
} else {
if (const auto *VD = dyn_cast<VarDecl>(D);
VD && VD->getAnyInitializer() &&
VD->getType().isConstant(Ctx.getASTContext()) && !VD->isWeak())
return revisit(VD);
}
return this->emitInvalidDeclRef(cast<DeclRefExpr>(E),
/*InitializerFailed=*/true, E);
}

return this->emitDummyPtr(D, E);
Expand Down
4 changes: 2 additions & 2 deletions clang/lib/AST/ByteCode/EvaluationResult.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -160,9 +160,9 @@ bool EvaluationResult::checkFullyInitialized(InterpState &S,
return true;

SourceLocation InitLoc;
if (const auto *D = Source.dyn_cast<const Decl *>())
if (const auto *D = dyn_cast<const Decl *>(Source))
InitLoc = cast<VarDecl>(D)->getAnyInitializer()->getExprLoc();
else if (const auto *E = Source.dyn_cast<const Expr *>())
else if (const auto *E = dyn_cast<const Expr *>(Source))
InitLoc = E->getExprLoc();

if (const Record *R = Ptr.getRecord())
Expand Down
4 changes: 2 additions & 2 deletions clang/lib/AST/VTableBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3831,8 +3831,8 @@ const VirtualBaseInfo &MicrosoftVTableContext::computeVBTableRelatedInformation(
unsigned VBTableIndex = 1 + VBI->VBTableIndices.size();
for (const auto &VB : RD->vbases()) {
const CXXRecordDecl *CurVBase = VB.getType()->getAsCXXRecordDecl();
if (!VBI->VBTableIndices.count(CurVBase))
VBI->VBTableIndices[CurVBase] = VBTableIndex++;
if (VBI->VBTableIndices.try_emplace(CurVBase, VBTableIndex).second)
++VBTableIndex;
}

return *VBI;
Expand Down
10 changes: 10 additions & 0 deletions clang/lib/CodeGen/CGBuiltin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20528,6 +20528,16 @@ Value *CodeGenFunction::EmitSPIRVBuiltinExpr(unsigned BuiltinID,
/*ReturnType=*/X->getType()->getScalarType(), Intrinsic::spv_distance,
ArrayRef<Value *>{X, Y}, nullptr, "spv.distance");
}
case SPIRV::BI__builtin_spirv_length: {
Value *X = EmitScalarExpr(E->getArg(0));
assert(E->getArg(0)->getType()->hasFloatingRepresentation() &&
"length operand must have a float representation");
assert(E->getArg(0)->getType()->isVectorType() &&
"length operand must be a vector");
return Builder.CreateIntrinsic(
/*ReturnType=*/X->getType()->getScalarType(), Intrinsic::spv_length,
ArrayRef<Value *>{X}, nullptr, "spv.length");
}
}
return nullptr;
}
Expand Down
1 change: 1 addition & 0 deletions clang/lib/Format/ContinuationIndenter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ static bool startsNextOperand(const FormatToken &Current) {
static bool mustBreakBinaryOperation(const FormatToken &Current,
const FormatStyle &Style) {
return Style.BreakBinaryOperations != FormatStyle::BBO_Never &&
Current.CanBreakBefore &&
(Style.BreakBeforeBinaryOperators == FormatStyle::BOS_None
? startsNextOperand
: isAlignableBinaryOperator)(Current);
Expand Down
6 changes: 3 additions & 3 deletions clang/lib/Format/UnwrappedLineParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -503,14 +503,14 @@ void UnwrappedLineParser::calculateBraceTypes(bool ExpectClassBody) {
auto *NextTok = Tokens->getNextNonComment();

if (!Line->InMacroBody && !Style.isTableGen()) {
// Skip PPDirective lines and comments.
// Skip PPDirective lines (except macro definitions) and comments.
while (NextTok->is(tok::hash)) {
NextTok = Tokens->getNextToken();
if (NextTok->is(tok::pp_not_keyword))
if (NextTok->isOneOf(tok::pp_not_keyword, tok::pp_define))
break;
do {
NextTok = Tokens->getNextToken();
} while (!NextTok->HasUnescapedNewline && NextTok->isNot(tok::eof));
} while (NextTok->NewlinesBefore == 0 && NextTok->isNot(tok::eof));

while (NextTok->is(tok::comment))
NextTok = Tokens->getNextToken();
Expand Down
8 changes: 4 additions & 4 deletions clang/lib/Headers/hlsl/hlsl_detail.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,11 @@ length_impl(T X) {
template <typename T, int N>
constexpr enable_if_t<is_same<float, T>::value || is_same<half, T>::value, T>
length_vec_impl(vector<T, N> X) {
#if (__has_builtin(__builtin_spirv_length))
return __builtin_spirv_length(X);
#else
return __builtin_elementwise_sqrt(__builtin_hlsl_dot(X, X));
#endif
}

template <typename T>
Expand All @@ -73,11 +77,7 @@ distance_impl(T X, T Y) {
template <typename T, int N>
constexpr enable_if_t<is_same<float, T>::value || is_same<half, T>::value, T>
distance_vec_impl(vector<T, N> X, vector<T, N> Y) {
#if (__has_builtin(__builtin_spirv_distance))
return __builtin_spirv_distance(X, Y);
#else
return length_vec_impl(X - Y);
#endif
}
} // namespace __detail
} // namespace hlsl
Expand Down
1 change: 1 addition & 0 deletions clang/lib/Sema/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ add_clang_library(clangSema
CodeCompleteConsumer.cpp
DeclSpec.cpp
DelayedDiagnostic.cpp
HeuristicResolver.cpp
HLSLExternalSemaSource.cpp
IdentifierResolver.cpp
JumpDiagnostics.cpp
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,14 @@
//
//===----------------------------------------------------------------------===//

#include "HeuristicResolver.h"
#include "clang/Sema/HeuristicResolver.h"
#include "clang/AST/ASTContext.h"
#include "clang/AST/CXXInheritance.h"
#include "clang/AST/DeclTemplate.h"
#include "clang/AST/ExprCXX.h"
#include "clang/AST/Type.h"

namespace clang {
namespace clangd {

namespace {

Expand Down Expand Up @@ -466,5 +465,4 @@ const Type *HeuristicResolver::getPointeeType(const Type *T) const {
return HeuristicResolverImpl(Ctx).getPointeeType(T);
}

} // namespace clangd
} // namespace clang
Loading

0 comments on commit f428ca6

Please sign in to comment.