Skip to content

Commit

Permalink
merge main into amd-staging
Browse files Browse the repository at this point in the history
Change-Id: I638ffe274cda77fba4ad0aa6ce7b5cc692f00d83
  • Loading branch information
Jenkins committed Jun 15, 2024
2 parents 36526f6 + ef01c75 commit d4b4156
Show file tree
Hide file tree
Showing 66 changed files with 2,510 additions and 1,504 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,13 @@ void MoveConstArgCheck::registerMatchers(MatchFinder *Finder) {
unless(isInTemplateInstantiation()))
.bind("call-move");

Finder->addMatcher(MoveCallMatcher, this);
Finder->addMatcher(
expr(anyOf(
castExpr(hasSourceExpression(MoveCallMatcher)),
cxxConstructExpr(hasDeclaration(cxxConstructorDecl(anyOf(
isCopyConstructor(), isMoveConstructor()))),
hasArgument(0, MoveCallMatcher)))),
this);

auto ConstTypeParmMatcher =
qualType(references(isConstQualified())).bind("invocation-parm-type");
Expand Down
4 changes: 4 additions & 0 deletions clang-tools-extra/docs/ReleaseNotes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,10 @@ Changes in existing checks
- Improved :doc:`modernize-use-using <clang-tidy/checks/modernize/use-using>`
check by adding support for detection of typedefs declared on function level.

- Improved :doc:`performance-move-const-arg
<clang-tidy/checks/performance/move-const-arg>` check by ignoring
``std::move()`` calls when their target is used as an rvalue.

- Improved :doc:`performance-unnecessary-copy-initialization
<clang-tidy/checks/performance/unnecessary-copy-initialization>` check by
detecting more cases of constant access. In particular, pointers can be
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,14 +114,18 @@ void f8() {
int f9() { return M2(1); }

template <typename T>
T f10(const int x10) {
T f_unknown_target(const int x10) {
return std::move(x10);
// CHECK-MESSAGES: :[[@LINE-1]]:10: warning: std::move of the const variable 'x10' of the trivially-copyable type 'const int' has no effect; remove std::move() [performance-move-const-arg]
// CHECK-FIXES: return x10;
}

void f11() {
f10<int>(1);
f10<double>(1);
f_unknown_target<int>(1);
f_unknown_target<double>(1);
}

A&& f_return_right_ref() {
static A a{};
return std::move(a);
}

class NoMoveSemantics {
Expand Down
3 changes: 3 additions & 0 deletions clang/docs/UsersManual.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3347,6 +3347,9 @@ below. If multiple flags are present, the last one is used.
By default, Clang does not emit type information for types that are defined
but not used in a program. To retain the debug info for these unused types,
the negation **-fno-eliminate-unused-debug-types** can be used.
This can be particulary useful on Windows, when using NATVIS files that
can reference const symbols that would otherwise be stripped, even in full
debug or standalone debug modes.

Controlling Macro Debug Info Generation
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Expand Down
2 changes: 1 addition & 1 deletion clang/include/clang/Driver/Options.td
Original file line number Diff line number Diff line change
Expand Up @@ -2124,7 +2124,7 @@ def fno_elide_type : Flag<["-"], "fno-elide-type">, Group<f_Group>,
MarshallingInfoNegativeFlag<DiagnosticOpts<"ElideType">>;
def feliminate_unused_debug_symbols : Flag<["-"], "feliminate-unused-debug-symbols">, Group<f_Group>;
defm eliminate_unused_debug_types : OptOutCC1FFlag<"eliminate-unused-debug-types",
"Do not emit ", "Emit ", " debug info for defined but unused types">;
"Do not emit ", "Emit ", " debug info for defined but unused types", [ClangOption, CLOption]>;
def femit_all_decls : Flag<["-"], "femit-all-decls">, Group<f_Group>,
Visibility<[ClangOption, CC1Option]>,
HelpText<"Emit all declarations, even if unused">,
Expand Down
4 changes: 3 additions & 1 deletion clang/include/clang/Lex/HeaderSearch.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,9 @@ struct HeaderFileInfo {
LLVM_PREFERRED_TYPE(bool)
unsigned isModuleHeader : 1;

/// Whether this header is a `textual header` in a module.
/// Whether this header is a `textual header` in a module. If a header is
/// textual in one module and normal in another module, this bit will not be
/// set, only `isModuleHeader`.
LLVM_PREFERRED_TYPE(bool)
unsigned isTextualModuleHeader : 1;

Expand Down
60 changes: 60 additions & 0 deletions clang/lib/AST/Interp/ByteCodeExprGen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,7 @@ bool ByteCodeExprGen<Emitter>::VisitCastExpr(const CastExpr *CE) {
case CK_NonAtomicToAtomic:
case CK_NoOp:
case CK_UserDefinedConversion:
case CK_AddressSpaceConversion:
return this->delegate(SubExpr);

case CK_BitCast: {
Expand Down Expand Up @@ -2734,6 +2735,65 @@ bool ByteCodeExprGen<Emitter>::VisitShuffleVectorExpr(
return true;
}

template <class Emitter>
bool ByteCodeExprGen<Emitter>::VisitExtVectorElementExpr(
const ExtVectorElementExpr *E) {
const Expr *Base = E->getBase();

SmallVector<uint32_t, 4> Indices;
E->getEncodedElementAccess(Indices);

if (Indices.size() == 1) {
if (!this->visit(Base))
return false;

if (E->isGLValue()) {
if (!this->emitConstUint32(Indices[0], E))
return false;
return this->emitArrayElemPtrPop(PT_Uint32, E);
}
// Else, also load the value.
return this->emitArrayElemPop(classifyPrim(E->getType()), Indices[0], E);
}

// Create a local variable for the base.
unsigned BaseOffset = allocateLocalPrimitive(Base, PT_Ptr, /*IsConst=*/true,
/*IsExtended=*/false);
if (!this->visit(Base))
return false;
if (!this->emitSetLocal(PT_Ptr, BaseOffset, E))
return false;

// Now the vector variable for the return value.
if (!Initializing) {
std::optional<unsigned> ResultIndex;
ResultIndex = allocateLocal(E);
if (!ResultIndex)
return false;
if (!this->emitGetPtrLocal(*ResultIndex, E))
return false;
}

assert(Indices.size() == E->getType()->getAs<VectorType>()->getNumElements());

PrimType ElemT =
classifyPrim(E->getType()->getAs<VectorType>()->getElementType());
uint32_t DstIndex = 0;
for (uint32_t I : Indices) {
if (!this->emitGetLocal(PT_Ptr, BaseOffset, E))
return false;
if (!this->emitArrayElemPop(ElemT, I, E))
return false;
if (!this->emitInitElem(ElemT, DstIndex, E))
return false;
++DstIndex;
}

// Leave the result pointer on the stack.
assert(!DiscardResult);
return true;
}

template <class Emitter>
bool ByteCodeExprGen<Emitter>::VisitObjCBoxedExpr(const ObjCBoxedExpr *E) {
if (!E->isExpressibleAsConstantInitializer())
Expand Down
1 change: 1 addition & 0 deletions clang/lib/AST/Interp/ByteCodeExprGen.h
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ class ByteCodeExprGen : public ConstStmtVisitor<ByteCodeExprGen<Emitter>, bool>,
bool VisitAddrLabelExpr(const AddrLabelExpr *E);
bool VisitConvertVectorExpr(const ConvertVectorExpr *E);
bool VisitShuffleVectorExpr(const ShuffleVectorExpr *E);
bool VisitExtVectorElementExpr(const ExtVectorElementExpr *E);
bool VisitObjCBoxedExpr(const ObjCBoxedExpr *E);

protected:
Expand Down
4 changes: 3 additions & 1 deletion clang/lib/AST/Interp/EvaluationResult.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,9 @@ bool EvaluationResult::checkFullyInitialized(InterpState &S,
const Pointer &Ptr) const {
assert(Source);
assert(empty());
assert(!Ptr.isZero());

if (Ptr.isZero())
return true;

SourceLocation InitLoc;
if (const auto *D = Source.dyn_cast<const Decl *>())
Expand Down
13 changes: 10 additions & 3 deletions clang/lib/Lex/HeaderSearch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1313,11 +1313,18 @@ OptionalFileEntryRef HeaderSearch::LookupSubframeworkHeader(
// File Info Management.
//===----------------------------------------------------------------------===//

static bool moduleMembershipNeedsMerge(const HeaderFileInfo *HFI,
ModuleMap::ModuleHeaderRole Role) {
if (ModuleMap::isModular(Role))
return !HFI->isModuleHeader || HFI->isTextualModuleHeader;
if (!HFI->isModuleHeader && (Role & ModuleMap::TextualHeader))
return !HFI->isTextualModuleHeader;
return false;
}

static void mergeHeaderFileInfoModuleBits(HeaderFileInfo &HFI,
bool isModuleHeader,
bool isTextualModuleHeader) {
assert((!isModuleHeader || !isTextualModuleHeader) &&
"A header can't build with a module and be textual at the same time");
HFI.isModuleHeader |= isModuleHeader;
if (HFI.isModuleHeader)
HFI.isTextualModuleHeader = false;
Expand Down Expand Up @@ -1432,7 +1439,7 @@ void HeaderSearch::MarkFileModuleHeader(FileEntryRef FE,
if ((Role & ModuleMap::ExcludedHeader))
return;
auto *HFI = getExistingFileInfo(FE);
if (HFI && HFI->isModuleHeader)
if (HFI && !moduleMembershipNeedsMerge(HFI, Role))
return;
}

Expand Down
13 changes: 13 additions & 0 deletions clang/test/AST/Interp/cxx20.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -814,3 +814,16 @@ namespace GH64949 {
// both-note {{subobject 'g' is not initialized}} \
// both-warning {{expression result unused}}
}

/// This used to cause an assertion failure inside EvaluationResult::checkFullyInitialized.
namespace CheckingNullPtrForInitialization {
struct X {
consteval operator const char *() const {
return nullptr;
}
};
const char *f() {
constexpr X x;
return x;
}
}
11 changes: 11 additions & 0 deletions clang/test/AST/Interp/vectors.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,3 +70,14 @@ namespace BoolToSignedIntegralCast{
static_assert(intsT[2] == -1, "");// ref-error {{not an integral constant expression}}
static_assert(intsT[3] == -1, "");// ref-error {{not an integral constant expression}}
}

namespace VectorElementExpr {
typedef int int2 __attribute__((ext_vector_type(2)));
typedef int int4 __attribute__((ext_vector_type(4)));
constexpr int oneElt = int4(3).x;
static_assert(oneElt == 3);

constexpr int2 twoElts = ((int4){11, 22, 33, 44}).yz;
static_assert(twoElts.x == 22, ""); // ref-error {{not an integral constant expression}}
static_assert(twoElts.y == 33, ""); // ref-error {{not an integral constant expression}}
}
1 change: 1 addition & 0 deletions clang/test/CodeGenOpenCLCXX/constexpr.clcpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// RUN: %clang_cc1 %s -triple spir-unknown-unknown -O0 -emit-llvm -o - | FileCheck %s
// RUN: %clang_cc1 %s -triple spir-unknown-unknown -O0 -emit-llvm -o - -fexperimental-new-constant-interpreter | FileCheck %s

typedef int int2 __attribute__((ext_vector_type(2)));
typedef int int4 __attribute__((ext_vector_type(4)));
Expand Down
2 changes: 2 additions & 0 deletions clang/test/Driver/cl-options.c
Original file line number Diff line number Diff line change
Expand Up @@ -698,6 +698,8 @@
// RUN: -Wunused-variable \
// RUN: -fmacro-backtrace-limit=0 \
// RUN: -fstandalone-debug \
// RUN: -feliminate-unused-debug-types \
// RUN: -fno-eliminate-unused-debug-types \
// RUN: -flimit-debug-info \
// RUN: -flto \
// RUN: -fmerge-all-constants \
Expand Down
68 changes: 68 additions & 0 deletions clang/unittests/Lex/HeaderSearchTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -323,5 +323,73 @@ TEST_F(HeaderSearchTest, HeaderMapFrameworkLookup) {
EXPECT_EQ(Search.getIncludeNameForHeader(FE), "Foo/Foo.h");
}

TEST_F(HeaderSearchTest, HeaderFileInfoMerge) {
auto AddHeader = [&](std::string HeaderPath) -> FileEntryRef {
VFS->addFile(HeaderPath, 0,
llvm::MemoryBuffer::getMemBufferCopy("", HeaderPath),
/*User=*/std::nullopt, /*Group=*/std::nullopt,
llvm::sys::fs::file_type::regular_file);
return *FileMgr.getOptionalFileRef(HeaderPath);
};

class MockExternalHeaderFileInfoSource : public ExternalHeaderFileInfoSource {
HeaderFileInfo GetHeaderFileInfo(FileEntryRef FE) {
HeaderFileInfo HFI;
auto FileName = FE.getName();
if (FileName == ModularPath)
HFI.mergeModuleMembership(ModuleMap::NormalHeader);
else if (FileName == TextualPath)
HFI.mergeModuleMembership(ModuleMap::TextualHeader);
HFI.External = true;
HFI.IsValid = true;
return HFI;
}

public:
std::string ModularPath = "/modular.h";
std::string TextualPath = "/textual.h";
};

auto ExternalSource = new MockExternalHeaderFileInfoSource();
Search.SetExternalSource(ExternalSource);

// Everything should start out external.
auto ModularFE = AddHeader(ExternalSource->ModularPath);
auto TextualFE = AddHeader(ExternalSource->TextualPath);
EXPECT_TRUE(Search.getExistingFileInfo(ModularFE)->External);
EXPECT_TRUE(Search.getExistingFileInfo(TextualFE)->External);

// Marking the same role should keep it external
Search.MarkFileModuleHeader(ModularFE, ModuleMap::NormalHeader,
/*isCompilingModuleHeader=*/false);
Search.MarkFileModuleHeader(TextualFE, ModuleMap::TextualHeader,
/*isCompilingModuleHeader=*/false);
EXPECT_TRUE(Search.getExistingFileInfo(ModularFE)->External);
EXPECT_TRUE(Search.getExistingFileInfo(TextualFE)->External);

// textual -> modular should update the HFI, but modular -> textual should be
// a no-op.
Search.MarkFileModuleHeader(ModularFE, ModuleMap::TextualHeader,
/*isCompilingModuleHeader=*/false);
Search.MarkFileModuleHeader(TextualFE, ModuleMap::NormalHeader,
/*isCompilingModuleHeader=*/false);
auto ModularFI = Search.getExistingFileInfo(ModularFE);
auto TextualFI = Search.getExistingFileInfo(TextualFE);
EXPECT_TRUE(ModularFI->External);
EXPECT_TRUE(ModularFI->isModuleHeader);
EXPECT_FALSE(ModularFI->isTextualModuleHeader);
EXPECT_FALSE(TextualFI->External);
EXPECT_TRUE(TextualFI->isModuleHeader);
EXPECT_FALSE(TextualFI->isTextualModuleHeader);

// Compiling the module should make the HFI local.
Search.MarkFileModuleHeader(ModularFE, ModuleMap::NormalHeader,
/*isCompilingModuleHeader=*/true);
Search.MarkFileModuleHeader(TextualFE, ModuleMap::NormalHeader,
/*isCompilingModuleHeader=*/true);
EXPECT_FALSE(Search.getExistingFileInfo(ModularFE)->External);
EXPECT_FALSE(Search.getExistingFileInfo(TextualFE)->External);
}

} // namespace
} // namespace clang
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
// XFAIL: libcpp-has-no-experimental-tzdb
// XFAIL: availability-tzdb-missing

// TODO TZDB Investigate why this fails.
// UNSUPPORTED: target={{.*}}

// <chrono>

// class time_zone;
Expand Down
4 changes: 1 addition & 3 deletions lldb/source/Utility/Scalar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -753,9 +753,7 @@ bool Scalar::SignExtend(uint32_t sign_bit_pos) {
return false;

case Scalar::e_int:
if (max_bit_pos == sign_bit_pos)
return true;
else if (sign_bit_pos < (max_bit_pos - 1)) {
if (sign_bit_pos < (max_bit_pos - 1)) {
llvm::APInt sign_bit = llvm::APInt::getSignMask(sign_bit_pos + 1);
llvm::APInt bitwize_and = m_integer & sign_bit;
if (bitwize_and.getBoolValue()) {
Expand Down
4 changes: 4 additions & 0 deletions llvm/include/llvm/CodeGen/GlobalISel/Utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -585,5 +585,9 @@ bool isGuaranteedNotToBePoison(Register Reg, const MachineRegisterInfo &MRI,
bool isGuaranteedNotToBeUndef(Register Reg, const MachineRegisterInfo &MRI,
unsigned Depth = 0);

/// Get the type back from LLT. It won't be 100 percent accurate but returns an
/// estimate of the type.
Type *getTypeForLLT(LLT Ty, LLVMContext &C);

} // End namespace llvm.
#endif
Loading

0 comments on commit d4b4156

Please sign in to comment.