Skip to content

Commit

Permalink
merge main into amd-staging
Browse files Browse the repository at this point in the history
Change-Id: I0055f01f222304615750e48ef2e35130d5b5751e
  • Loading branch information
Jenkins committed Sep 2, 2024
2 parents 6f9c93f + 55eb93b commit aacf4d7
Show file tree
Hide file tree
Showing 82 changed files with 6,093 additions and 1,967 deletions.
669 changes: 367 additions & 302 deletions clang-tools-extra/clangd/TidyFastChecks.inc

Large diffs are not rendered by default.

27 changes: 23 additions & 4 deletions clang-tools-extra/include-cleaner/lib/WalkAST.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include "clang/AST/DeclTemplate.h"
#include "clang/AST/Expr.h"
#include "clang/AST/ExprCXX.h"
#include "clang/AST/NestedNameSpecifier.h"
#include "clang/AST/RecursiveASTVisitor.h"
#include "clang/AST/TemplateBase.h"
#include "clang/AST/TemplateName.h"
Expand All @@ -23,9 +24,11 @@
#include "clang/Basic/IdentifierTable.h"
#include "clang/Basic/SourceLocation.h"
#include "clang/Basic/Specifiers.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/STLFunctionalExtras.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/Support/Casting.h"
#include "llvm/Support/ErrorHandling.h"

namespace clang::include_cleaner {
namespace {
Expand Down Expand Up @@ -125,6 +128,24 @@ class ASTWalker : public RecursiveASTVisitor<ASTWalker> {
return true;
}

bool qualifierIsNamespaceOrNone(DeclRefExpr *DRE) {
const auto *Qual = DRE->getQualifier();
if (!Qual)
return true;
switch (Qual->getKind()) {
case NestedNameSpecifier::Namespace:
case NestedNameSpecifier::NamespaceAlias:
case NestedNameSpecifier::Global:
return true;
case NestedNameSpecifier::TypeSpec:
case NestedNameSpecifier::TypeSpecWithTemplate:
case NestedNameSpecifier::Super:
case NestedNameSpecifier::Identifier:
return false;
}
llvm_unreachable("Unknown value for NestedNameSpecifierKind");
}

bool VisitDeclRefExpr(DeclRefExpr *DRE) {
auto *FD = DRE->getFoundDecl();
// Prefer the underlying decl if FoundDecl isn't a shadow decl, e.g:
Expand All @@ -146,10 +167,8 @@ class ASTWalker : public RecursiveASTVisitor<ASTWalker> {
//
// If it's an enum constant, it must be due to prior decl. Report references
// to it when qualifier isn't a type.
if (llvm::isa<EnumConstantDecl>(FD)) {
if (!DRE->getQualifier() || DRE->getQualifier()->getAsNamespace())
report(DRE->getLocation(), FD);
}
if (llvm::isa<EnumConstantDecl>(FD) && qualifierIsNamespaceOrNone(DRE))
report(DRE->getLocation(), FD);
return true;
}

Expand Down
3 changes: 3 additions & 0 deletions clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -534,6 +534,9 @@ TEST(WalkAST, Enums) {
testWalk(R"(namespace ns { enum E { A = 42 }; }
struct S { using ns::E::A; };)",
"int e = S::^A;");
testWalk(R"(namespace ns { enum E { $explicit^A = 42 }; })",
"namespace z = ns; int e = z::^A;");
testWalk(R"(enum E { $explicit^A = 42 };)", "int e = ::^A;");
}

TEST(WalkAST, InitializerList) {
Expand Down
6 changes: 6 additions & 0 deletions clang/docs/Multilib.rst
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,12 @@ For a more comprehensive example see
# to be a match.
Flags: [--target=thumbv7m-none-eabi, -mfpu=fpv4-sp-d16]
# If there is no multilib available for a particular set of flags, and the
# other multilibs are not adequate fallbacks, then you can define a variant
# record with a FatalError key in place of the Dir key.
- FatalError: this multilib collection has no hard-float ABI support
Flags: [--target=thumbv7m-none-eabi, -mfloat-abi=hard]
# The second section of the file is a list of regular expressions that are
# used to map from flags generated from command line options to custom flags.
Expand Down
6 changes: 3 additions & 3 deletions clang/include/clang/AST/ASTContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -2722,9 +2722,9 @@ class ASTContext : public RefCountedBase<ASTContext> {
const ObjCMethodDecl *MethodImp);

bool UnwrapSimilarTypes(QualType &T1, QualType &T2,
bool AllowPiMismatch = true);
bool AllowPiMismatch = true) const;
void UnwrapSimilarArrayTypes(QualType &T1, QualType &T2,
bool AllowPiMismatch = true);
bool AllowPiMismatch = true) const;

/// Determine if two types are similar, according to the C++ rules. That is,
/// determine if they are the same other than qualifiers on the initial
Expand All @@ -2733,7 +2733,7 @@ class ASTContext : public RefCountedBase<ASTContext> {
///
/// Clang offers a number of qualifiers in addition to the C++ qualifiers;
/// those qualifiers are also ignored in the 'similarity' check.
bool hasSimilarType(QualType T1, QualType T2);
bool hasSimilarType(QualType T1, QualType T2) const;

/// Determine if two types are similar, ignoring only CVR qualifiers.
bool hasCvrSimilarType(QualType T1, QualType T2);
Expand Down
2 changes: 2 additions & 0 deletions clang/include/clang/Basic/DiagnosticDriverKinds.td
Original file line number Diff line number Diff line change
Expand Up @@ -831,6 +831,8 @@ def warn_drv_missing_multilib : Warning<
InGroup<DiagGroup<"missing-multilib">>;
def note_drv_available_multilibs : Note<
"available multilibs are:%0">;
def err_drv_multilib_custom_error : Error<
"multilib configuration error: %0">;

def err_drv_experimental_crel : Error<
"-Wa,--allow-experimental-crel must be specified to use -Wa,--crel. "
Expand Down
12 changes: 5 additions & 7 deletions clang/include/clang/Basic/TargetCXXABI.def
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
/// many compilers, including Clang and GCC.
///
/// It is documented here:
/// http://www.codesourcery.com/public/cxx-abi/
/// http://itanium-cxx-abi.github.io/cxx-abi/
ITANIUM_CXXABI(GenericItanium, "itanium")

/// The generic ARM ABI is a modified version of the Itanium ABI
Expand All @@ -46,8 +46,7 @@ ITANIUM_CXXABI(GenericItanium, "itanium")
/// - and more!
///
/// It is documented here:
/// http://infocenter.arm.com
/// /help/topic/com.arm.doc.ihi0041c/IHI0041C_cppabi.pdf
/// https://github.com/ARM-software/abi-aa/blob/main/cppabi32/cppabi32.rst
ITANIUM_CXXABI(GenericARM, "arm")

/// The iOS ABI is a partial implementation of the ARM ABI.
Expand All @@ -63,10 +62,6 @@ ITANIUM_CXXABI(iOS, "ios")

/// The iOS 64-bit and macOS 64-bit ARM ABI follows ARM's published 64-bit
/// ABI more closely, but we don't guarantee to follow it perfectly.
///
/// It is documented here:
/// http://infocenter.arm.com
/// /help/topic/com.arm.doc.ihi0059a/IHI0059A_cppabi64.pdf
ITANIUM_CXXABI(AppleARM64, "applearm64")

/// WatchOS is a modernisation of the iOS ABI, which roughly means it's
Expand All @@ -80,6 +75,9 @@ ITANIUM_CXXABI(WatchOS, "watchos")
/// The relevant changes from the generic ABI in this case are:
/// - representation of member function pointers adjusted as in ARM.
/// - guard variables are smaller.
///
/// It is documented here:
/// https://github.com/ARM-software/abi-aa/blob/main/cppabi64/cppabi64.rst
ITANIUM_CXXABI(GenericAArch64, "aarch64")

/// The generic Mips ABI is a modified version of the Itanium ABI.
Expand Down
17 changes: 15 additions & 2 deletions clang/include/clang/Driver/Multilib.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,16 @@
#include "llvm/Support/SourceMgr.h"
#include <cassert>
#include <functional>
#include <optional>
#include <string>
#include <utility>
#include <vector>

namespace clang {
namespace driver {

class Driver;

/// This corresponds to a single GCC Multilib, or a segment of one controlled
/// by a command line flag.
/// See also MultilibBuilder for building a multilib by mutating it
Expand All @@ -48,13 +51,19 @@ class Multilib {
// directory is not mutually exclusive with anything else.
std::string ExclusiveGroup;

// Some Multilib objects don't actually represent library directories you can
// select. Instead, they represent failures of multilib selection, of the
// form 'Sorry, we don't have any library compatible with these constraints'.
std::optional<std::string> FatalError;

public:
/// GCCSuffix, OSSuffix & IncludeSuffix will be appended directly to the
/// sysroot string so they must either be empty or begin with a '/' character.
/// This is enforced with an assert in the constructor.
Multilib(StringRef GCCSuffix = {}, StringRef OSSuffix = {},
StringRef IncludeSuffix = {}, const flags_list &Flags = flags_list(),
StringRef ExclusiveGroup = {});
StringRef ExclusiveGroup = {},
std::optional<StringRef> FatalError = std::nullopt);

/// Get the detected GCC installation path suffix for the multi-arch
/// target variant. Always starts with a '/', unless empty
Expand Down Expand Up @@ -84,6 +93,10 @@ class Multilib {
{ return GCCSuffix.empty() && OSSuffix.empty() && IncludeSuffix.empty(); }

bool operator==(const Multilib &Other) const;

bool isFatalError() const { return FatalError.has_value(); }

const std::string &getFatalError() const { return FatalError.value(); }
};

raw_ostream &operator<<(raw_ostream &OS, const Multilib &M);
Expand Down Expand Up @@ -129,7 +142,7 @@ class MultilibSet {
const_iterator end() const { return Multilibs.end(); }

/// Select compatible variants, \returns false if none are compatible
bool select(const Multilib::flags_list &Flags,
bool select(const Driver &D, const Multilib::flags_list &Flags,
llvm::SmallVectorImpl<Multilib> &) const;

unsigned size() const { return Multilibs.size(); }
Expand Down
6 changes: 3 additions & 3 deletions clang/lib/AST/ASTContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6582,7 +6582,7 @@ QualType ASTContext::getUnqualifiedArrayType(QualType type,
/// \param AllowPiMismatch Allow the Pi1 and Pi2 to differ as described in
/// C++20 [conv.qual], if permitted by the current language mode.
void ASTContext::UnwrapSimilarArrayTypes(QualType &T1, QualType &T2,
bool AllowPiMismatch) {
bool AllowPiMismatch) const {
while (true) {
auto *AT1 = getAsArrayType(T1);
if (!AT1)
Expand Down Expand Up @@ -6633,7 +6633,7 @@ void ASTContext::UnwrapSimilarArrayTypes(QualType &T1, QualType &T2,
/// \return \c true if a pointer type was unwrapped, \c false if we reached a
/// pair of types that can't be unwrapped further.
bool ASTContext::UnwrapSimilarTypes(QualType &T1, QualType &T2,
bool AllowPiMismatch) {
bool AllowPiMismatch) const {
UnwrapSimilarArrayTypes(T1, T2, AllowPiMismatch);

const auto *T1PtrType = T1->getAs<PointerType>();
Expand Down Expand Up @@ -6669,7 +6669,7 @@ bool ASTContext::UnwrapSimilarTypes(QualType &T1, QualType &T2,
return false;
}

bool ASTContext::hasSimilarType(QualType T1, QualType T2) {
bool ASTContext::hasSimilarType(QualType T1, QualType T2) const {
while (true) {
Qualifiers Quals;
T1 = getUnqualifiedArrayType(T1, Quals);
Expand Down
8 changes: 2 additions & 6 deletions clang/lib/AST/ByteCode/Compiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1235,12 +1235,6 @@ bool Compiler<Emitter>::VisitImplicitValueInitExpr(
assert(RD);
if (RD->isInvalidDecl())
return false;
if (RD->isUnion()) {
// C++11 [dcl.init]p5: If T is a (possibly cv-qualified) union type, the
// object's first non-static named data member is zero-initialized
// FIXME
return false;
}

if (const auto *CXXRD = dyn_cast<CXXRecordDecl>(RD);
CXXRD && CXXRD->getNumVBases() > 0) {
Expand Down Expand Up @@ -3434,6 +3428,8 @@ bool Compiler<Emitter>::visitZeroRecordInitializer(const Record *R,
if (!this->emitFinishInitPop(E))
return false;

// C++11 [dcl.init]p5: If T is a (possibly cv-qualified) union type, the
// object's first non-static named data member is zero-initialized
if (R->isUnion())
break;
}
Expand Down
3 changes: 2 additions & 1 deletion clang/lib/AST/ByteCode/Function.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ bool Function::isVirtual() const {
static bool isUnevaluatedBuiltin(unsigned BuiltinID) {
return BuiltinID == Builtin::BI__builtin_classify_type ||
BuiltinID == Builtin::BI__builtin_os_log_format_buffer_size ||
BuiltinID == Builtin::BI__builtin_constant_p;
BuiltinID == Builtin::BI__builtin_constant_p ||
BuiltinID == Builtin::BI__noop;
}

bool Function::isUnevaluatedBuiltin() const {
Expand Down
4 changes: 4 additions & 0 deletions clang/lib/AST/ByteCode/InterpBuiltin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1593,6 +1593,10 @@ bool InterpretBuiltin(InterpState &S, CodePtr OpPC, const Function *F,
return false;
break;

case Builtin::BI__noop:
pushInteger(S, 0, Call->getType());
break;

default:
S.FFDiag(S.Current->getLocation(OpPC),
diag::note_invalid_subexpr_in_const_expr)
Expand Down
3 changes: 2 additions & 1 deletion clang/lib/Driver/Driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2319,7 +2319,8 @@ bool Driver::HandleImmediateArgs(Compilation &C) {

if (C.getArgs().hasArg(options::OPT_print_multi_lib)) {
for (const Multilib &Multilib : TC.getMultilibs())
llvm::outs() << Multilib << "\n";
if (!Multilib.isFatalError())
llvm::outs() << Multilib << "\n";
return false;
}

Expand Down
46 changes: 33 additions & 13 deletions clang/lib/Driver/Multilib.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "clang/Driver/Multilib.h"
#include "clang/Basic/LLVM.h"
#include "clang/Basic/Version.h"
#include "clang/Driver/Driver.h"
#include "llvm/ADT/DenseSet.h"
#include "llvm/ADT/SmallString.h"
#include "llvm/ADT/StringRef.h"
Expand All @@ -31,9 +32,10 @@ using namespace llvm::sys;

Multilib::Multilib(StringRef GCCSuffix, StringRef OSSuffix,
StringRef IncludeSuffix, const flags_list &Flags,
StringRef ExclusiveGroup)
StringRef ExclusiveGroup,
std::optional<StringRef> FatalError)
: GCCSuffix(GCCSuffix), OSSuffix(OSSuffix), IncludeSuffix(IncludeSuffix),
Flags(Flags), ExclusiveGroup(ExclusiveGroup) {
Flags(Flags), ExclusiveGroup(ExclusiveGroup), FatalError(FatalError) {
assert(GCCSuffix.empty() ||
(StringRef(GCCSuffix).front() == '/' && GCCSuffix.size() > 1));
assert(OSSuffix.empty() ||
Expand Down Expand Up @@ -94,7 +96,7 @@ MultilibSet &MultilibSet::FilterOut(FilterCallback F) {

void MultilibSet::push_back(const Multilib &M) { Multilibs.push_back(M); }

bool MultilibSet::select(const Multilib::flags_list &Flags,
bool MultilibSet::select(const Driver &D, const Multilib::flags_list &Flags,
llvm::SmallVectorImpl<Multilib> &Selected) const {
llvm::StringSet<> FlagSet(expandFlags(Flags));
Selected.clear();
Expand All @@ -121,6 +123,14 @@ bool MultilibSet::select(const Multilib::flags_list &Flags,
continue;
}

// If this multilib is actually a placeholder containing a fatal
// error message written by the multilib.yaml author, display that
// error message, and return failure.
if (M.isFatalError()) {
D.Diag(clang::diag::err_drv_multilib_custom_error) << M.getFatalError();
return false;
}

// Select this multilib.
Selected.push_back(M);
}
Expand Down Expand Up @@ -162,7 +172,8 @@ namespace {
static const VersionTuple MultilibVersionCurrent(1, 0);

struct MultilibSerialization {
std::string Dir;
std::string Dir; // if this record successfully selects a library dir
std::string FatalError; // if this record reports a fatal error message
std::vector<std::string> Flags;
std::string Group;
};
Expand Down Expand Up @@ -205,11 +216,16 @@ struct MultilibSetSerialization {

template <> struct llvm::yaml::MappingTraits<MultilibSerialization> {
static void mapping(llvm::yaml::IO &io, MultilibSerialization &V) {
io.mapRequired("Dir", V.Dir);
io.mapOptional("Dir", V.Dir);
io.mapOptional("FatalError", V.FatalError);
io.mapRequired("Flags", V.Flags);
io.mapOptional("Group", V.Group);
}
static std::string validate(IO &io, MultilibSerialization &V) {
if (V.Dir.empty() && V.FatalError.empty())
return "one of the 'Dir' and 'FatalError' keys must be specified";
if (!V.Dir.empty() && !V.FatalError.empty())
return "the 'Dir' and 'FatalError' keys may not both be specified";
if (StringRef(V.Dir).starts_with("/"))
return "paths must be relative but \"" + V.Dir + "\" starts with \"/\"";
return std::string{};
Expand Down Expand Up @@ -295,14 +311,18 @@ MultilibSet::parseYaml(llvm::MemoryBufferRef Input,
multilib_list Multilibs;
Multilibs.reserve(MS.Multilibs.size());
for (const auto &M : MS.Multilibs) {
std::string Dir;
if (M.Dir != ".")
Dir = "/" + M.Dir;
// We transfer M.Group straight into the ExclusiveGroup parameter for the
// Multilib constructor. If we later support more than one type of group,
// we'll have to look up the group name in MS.Groups, check its type, and
// decide what to do here.
Multilibs.emplace_back(Dir, Dir, Dir, M.Flags, M.Group);
if (!M.FatalError.empty()) {
Multilibs.emplace_back("", "", "", M.Flags, M.Group, M.FatalError);
} else {
std::string Dir;
if (M.Dir != ".")
Dir = "/" + M.Dir;
// We transfer M.Group straight into the ExclusiveGroup parameter for the
// Multilib constructor. If we later support more than one type of group,
// we'll have to look up the group name in MS.Groups, check its type, and
// decide what to do here.
Multilibs.emplace_back(Dir, Dir, Dir, M.Flags, M.Group);
}
}

return MultilibSet(std::move(Multilibs), std::move(MS.FlagMatchers));
Expand Down
Loading

0 comments on commit aacf4d7

Please sign in to comment.