Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions bolt/lib/Profile/DataAggregator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2215,7 +2215,7 @@ DataAggregator::writeAggregatedFile(StringRef OutputFilename) const {
OutFile << "boltedcollection\n";
if (opts::BasicAggregation) {
OutFile << "no_lbr";
for (const StringMapEntry<std::nullopt_t> &Entry : EventNames)
for (const StringMapEntry<EmptyStringSetTag> &Entry : EventNames)
OutFile << " " << Entry.getKey();
OutFile << "\n";

Expand Down Expand Up @@ -2291,7 +2291,7 @@ std::error_code DataAggregator::writeBATYAML(BinaryContext &BC,

ListSeparator LS(",");
raw_string_ostream EventNamesOS(BP.Header.EventNames);
for (const StringMapEntry<std::nullopt_t> &EventEntry : EventNames)
for (const StringMapEntry<EmptyStringSetTag> &EventEntry : EventNames)
EventNamesOS << LS << EventEntry.first().str();

BP.Header.Flags = opts::BasicAggregation ? BinaryFunction::PF_BASIC
Expand Down
2 changes: 1 addition & 1 deletion bolt/lib/Profile/YAMLProfileWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,7 @@ std::error_code YAMLProfileWriter::writeProfile(const RewriteInstance &RI) {
StringSet<> EventNames = RI.getProfileReader()->getEventNames();
if (!EventNames.empty()) {
std::string Sep;
for (const StringMapEntry<std::nullopt_t> &EventEntry : EventNames) {
for (const StringMapEntry<EmptyStringSetTag> &EventEntry : EventNames) {
BP.Header.EventNames += Sep + EventEntry.first().str();
Sep = ",";
}
Expand Down
57 changes: 39 additions & 18 deletions clang/lib/CodeGen/TargetBuiltins/NVPTX.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -375,28 +375,28 @@ static Value *MakeCpAsync(unsigned IntrinsicID, unsigned IntrinsicIDS,
CGF.EmitScalarExpr(E->getArg(1))});
}

static Value *MakeHalfType(unsigned IntrinsicID, unsigned BuiltinID,
const CallExpr *E, CodeGenFunction &CGF) {
static bool EnsureNativeHalfSupport(unsigned BuiltinID, const CallExpr *E,
CodeGenFunction &CGF) {
auto &C = CGF.CGM.getContext();
if (!(C.getLangOpts().NativeHalfType ||
!C.getTargetInfo().useFP16ConversionIntrinsics())) {
if (!C.getLangOpts().NativeHalfType &&
C.getTargetInfo().useFP16ConversionIntrinsics()) {
CGF.CGM.Error(E->getExprLoc(), C.BuiltinInfo.getQuotedName(BuiltinID) +
" requires native half type support.");
return nullptr;
return false;
}
return true;
}

if (BuiltinID == NVPTX::BI__nvvm_ldg_h || BuiltinID == NVPTX::BI__nvvm_ldg_h2)
return MakeLdg(CGF, E);

if (IntrinsicID == Intrinsic::nvvm_ldu_global_f)
return MakeLdu(IntrinsicID, CGF, E);
static Value *MakeHalfType(Function *Intrinsic, unsigned BuiltinID,
const CallExpr *E, CodeGenFunction &CGF) {
if (!EnsureNativeHalfSupport(BuiltinID, E, CGF))
return nullptr;

SmallVector<Value *, 16> Args;
auto *F = CGF.CGM.getIntrinsic(IntrinsicID);
auto *FTy = F->getFunctionType();
auto *FTy = Intrinsic->getFunctionType();
unsigned ICEArguments = 0;
ASTContext::GetBuiltinTypeError Error;
C.GetBuiltinType(BuiltinID, Error, &ICEArguments);
CGF.CGM.getContext().GetBuiltinType(BuiltinID, Error, &ICEArguments);
assert(Error == ASTContext::GE_None && "Should not codegen an error");
for (unsigned i = 0, e = E->getNumArgs(); i != e; ++i) {
assert((ICEArguments & (1 << i)) == 0);
Expand All @@ -407,8 +407,14 @@ static Value *MakeHalfType(unsigned IntrinsicID, unsigned BuiltinID,
Args.push_back(ArgValue);
}

return CGF.Builder.CreateCall(F, Args);
return CGF.Builder.CreateCall(Intrinsic, Args);
}

static Value *MakeHalfType(unsigned IntrinsicID, unsigned BuiltinID,
const CallExpr *E, CodeGenFunction &CGF) {
return MakeHalfType(CGF.CGM.getIntrinsic(IntrinsicID), BuiltinID, E, CGF);
}

} // namespace

Value *CodeGenFunction::EmitNVPTXBuiltinExpr(unsigned BuiltinID,
Expand Down Expand Up @@ -913,9 +919,14 @@ Value *CodeGenFunction::EmitNVPTXBuiltinExpr(unsigned BuiltinID,
}
// The following builtins require half type support
case NVPTX::BI__nvvm_ex2_approx_f16:
return MakeHalfType(Intrinsic::nvvm_ex2_approx_f16, BuiltinID, E, *this);
return MakeHalfType(
CGM.getIntrinsic(Intrinsic::nvvm_ex2_approx, Builder.getHalfTy()),
BuiltinID, E, *this);
case NVPTX::BI__nvvm_ex2_approx_f16x2:
return MakeHalfType(Intrinsic::nvvm_ex2_approx_f16x2, BuiltinID, E, *this);
return MakeHalfType(
CGM.getIntrinsic(Intrinsic::nvvm_ex2_approx,
FixedVectorType::get(Builder.getHalfTy(), 2)),
BuiltinID, E, *this);
case NVPTX::BI__nvvm_ff2f16x2_rn:
return MakeHalfType(Intrinsic::nvvm_ff2f16x2_rn, BuiltinID, E, *this);
case NVPTX::BI__nvvm_ff2f16x2_rn_relu:
Expand Down Expand Up @@ -1049,12 +1060,22 @@ Value *CodeGenFunction::EmitNVPTXBuiltinExpr(unsigned BuiltinID,
case NVPTX::BI__nvvm_fabs_d:
return Builder.CreateUnaryIntrinsic(Intrinsic::fabs,
EmitScalarExpr(E->getArg(0)));
case NVPTX::BI__nvvm_ex2_approx_d:
case NVPTX::BI__nvvm_ex2_approx_f:
return Builder.CreateUnaryIntrinsic(Intrinsic::nvvm_ex2_approx,
EmitScalarExpr(E->getArg(0)));
case NVPTX::BI__nvvm_ex2_approx_ftz_f:
return Builder.CreateUnaryIntrinsic(Intrinsic::nvvm_ex2_approx_ftz,
EmitScalarExpr(E->getArg(0)));
case NVPTX::BI__nvvm_ldg_h:
case NVPTX::BI__nvvm_ldg_h2:
return MakeHalfType(Intrinsic::not_intrinsic, BuiltinID, E, *this);
return EnsureNativeHalfSupport(BuiltinID, E, *this) ? MakeLdg(*this, E)
: nullptr;
case NVPTX::BI__nvvm_ldu_h:
case NVPTX::BI__nvvm_ldu_h2:
return MakeHalfType(Intrinsic::nvvm_ldu_global_f, BuiltinID, E, *this);
return EnsureNativeHalfSupport(BuiltinID, E, *this)
? MakeLdu(Intrinsic::nvvm_ldu_global_f, *this, E)
: nullptr;
case NVPTX::BI__nvvm_cp_async_ca_shared_global_4:
return MakeCpAsync(Intrinsic::nvvm_cp_async_ca_shared_global_4,
Intrinsic::nvvm_cp_async_ca_shared_global_4_s, *this, E,
Expand Down
12 changes: 8 additions & 4 deletions clang/lib/Driver/Driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2550,10 +2550,14 @@ bool Driver::HandleImmediateArgs(Compilation &C) {
}

if (C.getArgs().hasArg(options::OPT_print_runtime_dir)) {
if (std::optional<std::string> RuntimePath = TC.getRuntimePath())
llvm::outs() << *RuntimePath << '\n';
else
llvm::outs() << TC.getCompilerRTPath() << '\n';
for (auto RuntimePath :
{TC.getRuntimePath(), std::make_optional(TC.getCompilerRTPath())}) {
if (RuntimePath && getVFS().exists(*RuntimePath)) {
llvm::outs() << *RuntimePath << '\n';
return false;
}
}
llvm::outs() << "(runtime dir is not present)" << '\n';
return false;
}

Expand Down
2 changes: 1 addition & 1 deletion clang/lib/Headers/hlsl/hlsl_compat_overloads.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
//===----------------------------------------------------------------------===//

#ifndef _HLSL_COMPAT_OVERLOADS_H_
#define _HLSl_COMPAT_OVERLOADS_H_
#define _HLSL_COMPAT_OVERLOADS_H_

namespace hlsl {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
typedef __fp16 __fp16v2 __attribute__((ext_vector_type(2)));

// CHECK: call half @llvm.nvvm.ex2.approx.f16(half {{.*}})
// CHECK: call <2 x half> @llvm.nvvm.ex2.approx.f16x2(<2 x half> {{.*}})
// CHECK: call <2 x half> @llvm.nvvm.ex2.approx.v2f16(<2 x half> {{.*}})
// CHECK: call half @llvm.nvvm.fma.rn.relu.f16(half {{.*}}, half {{.*}}, half {{.*}})
// CHECK: call half @llvm.nvvm.fma.rn.ftz.relu.f16(half {{.*}}, half {{.*}}, half {{.*}})
// CHECK: call <2 x half> @llvm.nvvm.fma.rn.relu.f16x2(<2 x half> {{.*}}, <2 x half> {{.*}}, <2 x half> {{.*}})
Expand Down
2 changes: 1 addition & 1 deletion clang/test/CodeGen/builtins-nvptx-native-half-type.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ __device__ void nvvm_ex2_sm75() {
#if __CUDA_ARCH__ >= 750
// CHECK_PTX70_SM75: call half @llvm.nvvm.ex2.approx.f16
__nvvm_ex2_approx_f16(0.1f16);
// CHECK_PTX70_SM75: call <2 x half> @llvm.nvvm.ex2.approx.f16x2
// CHECK_PTX70_SM75: call <2 x half> @llvm.nvvm.ex2.approx.v2f16
__nvvm_ex2_approx_f16x2({0.1f16, 0.7f16});
#endif
// CHECK: ret void
Expand Down
2 changes: 1 addition & 1 deletion lld/MachO/Arch/X86_64.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ int64_t X86_64::getEmbeddedAddend(MemoryBufferRef mb, uint64_t offset,
void X86_64::relocateOne(uint8_t *loc, const Reloc &r, uint64_t value,
uint64_t relocVA) const {
if (r.pcrel) {
uint64_t pc = relocVA + (1 << r.length) + pcrelOffset(r.type);
uint64_t pc = relocVA + (1ull << r.length) + pcrelOffset(r.type);
value -= pc;
}

Expand Down
3 changes: 3 additions & 0 deletions lld/MachO/InputSection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,9 @@ WordLiteralInputSection::WordLiteralInputSection(const Section &section,
}

uint64_t WordLiteralInputSection::getOffset(uint64_t off) const {
if (off >= data.size())
fatal(toString(this) + ": offset is outside the section");

auto *osec = cast<WordLiteralSection>(parent);
const uintptr_t buf = reinterpret_cast<uintptr_t>(data.data());
switch (sectionType(getFlags())) {
Expand Down
45 changes: 45 additions & 0 deletions lld/test/MachO/invalid/bad-offsets.s
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
## Test that we properly detect and report out-of-bounds offsets in literal sections.
## We're intentionally testing fatal errors (for malformed input files), and
## fatal errors aren't supported for testing when main is run twice.
# XFAIL: main-run-twice

# REQUIRES: x86
# RUN: rm -rf %t; split-file %s %t

## Test WordLiteralInputSection bounds checking
# RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %t/word-literal.s -o %t/word-literal.o
# RUN: not %lld -dylib %t/word-literal.o -o /dev/null 2>&1 | FileCheck %s --check-prefix=WORD

## Test CStringInputSection bounds checking
# RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %t/cstring.s -o %t/cstring.o
# RUN: not %lld -dylib %t/cstring.o -o /dev/null 2>&1 | FileCheck %s --check-prefix=CSTRING

# WORD: error: {{.*}}word-literal.o:(__literal4): offset is outside the section
# CSTRING: error: {{.*}}cstring.o:(__cstring): offset is outside the section

#--- word-literal.s
.section __TEXT,__literal4,4byte_literals
L_literal:
.long 0x01020304

.text
.globl _main
_main:
# We use a subtractor expression to force a section relocation. Symbol relocations
# don't trigger the error.
.long L_literal - _main + 4

.subsections_via_symbols

#--- cstring.s
## Create a cstring section with a reference that points past the end
.cstring
L_str:
.asciz "foo"

.text
.globl _main
_main:
.long L_str - _main + 4

.subsections_via_symbols
5 changes: 5 additions & 0 deletions llvm/docs/CommandGuide/llvm-config.rst
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,11 @@ OPTIONS

Print the installation prefix for LLVM.

**--quote-paths**

Quote and escape paths when needed, most notably when a quote, space, backslash
or dollar sign characters are present in the path.

**--shared-mode**

Print how the provided components can be collectively linked (`shared` or `static`).
Expand Down
22 changes: 11 additions & 11 deletions llvm/docs/LangRef.rst
Original file line number Diff line number Diff line change
Expand Up @@ -668,7 +668,7 @@ representation is not just an integer address are called "non-integral".
Non-integral pointers have at least one of the following three properties:

* the pointer representation contains non-address bits
* the pointer representation is unstable (may changed at any time in a
* the pointer representation is unstable (may change at any time in a
target-specific way)
* the pointer representation has external state

Expand Down Expand Up @@ -757,7 +757,7 @@ The following restrictions apply to IR level optimization passes:

The ``inttoptr`` instruction does not recreate the external state and therefore
it is target dependent whether it can be used to create a dereferenceable
pointer. In general passes should assume that the result of such an inttoptr
pointer. In general passes should assume that the result of such an ``inttoptr``
is not dereferenceable. For example, on CHERI targets an ``inttoptr`` will
yield a capability with the external state (the validity tag bit) set to zero,
which will cause any dereference to trap.
Expand All @@ -784,7 +784,7 @@ be performed as loads and stores of the correct type since stores of other
types may not propagate the external data.
Therefore it is not legal to convert an existing load/store (or a
``llvm.memcpy`` / ``llvm.memmove`` intrinsic) of pointer types with external
state to a load/store of an integer type with same bitwidth, as that may drop
state to a load/store of an integer type with the same bitwidth, as that may drop
the external state.


Expand All @@ -806,7 +806,7 @@ Global variables can optionally specify a :ref:`linkage type <linkage>`.
Either global variable definitions or declarations may have an explicit section
to be placed in and may have an optional explicit alignment specified. If there
is a mismatch between the explicit or inferred section information for the
variable declaration and its definition the resulting behavior is undefined.
variable declaration and its definition, the resulting behavior is undefined.

A variable may be defined as a global ``constant``, which indicates that
the contents of the variable will **never** be modified (enabling better
Expand Down Expand Up @@ -1334,7 +1334,7 @@ Currently, only the following parameter attributes are defined:
The byval type argument indicates the in-memory value type.

The byval attribute also supports specifying an alignment with the
align attribute. It indicates the alignment of the stack slot to
``align`` attribute. It indicates the alignment of the stack slot to
form and the known alignment of the pointer specified to the call
site. If the alignment is not specified, then the code generator
makes a target-specific assumption.
Expand All @@ -1355,7 +1355,7 @@ Currently, only the following parameter attributes are defined:

This is not a valid attribute for return values.

The alignment for an ``byref`` parameter can be explicitly
The alignment for a ``byref`` parameter can be explicitly
specified by combining it with the ``align`` attribute, similar to
``byval``. If the alignment is not specified, then the code generator
makes a target-specific assumption.
Expand All @@ -1382,7 +1382,7 @@ Currently, only the following parameter attributes are defined:
The preallocated attribute requires a type argument.

The preallocated attribute also supports specifying an alignment with the
align attribute. It indicates the alignment of the stack slot to
``align`` attribute. It indicates the alignment of the stack slot to
form and the known alignment of the pointer specified to the call
site. If the alignment is not specified, then the code generator
makes a target-specific assumption.
Expand Down Expand Up @@ -1550,15 +1550,15 @@ Currently, only the following parameter attributes are defined:

``nonnull``
This indicates that the parameter or return pointer is not null. This
attribute may only be applied to pointer typed parameters. This is not
attribute may only be applied to pointer-typed parameters. This is not
checked or enforced by LLVM; if the parameter or return pointer is null,
:ref:`poison value <poisonvalues>` is returned or passed instead.
The ``nonnull`` attribute should be combined with the ``noundef`` attribute
to ensure a pointer is not null or otherwise the behavior is undefined.

``dereferenceable(<n>)``
This indicates that the parameter or return pointer is dereferenceable. This
attribute may only be applied to pointer typed parameters. A pointer that
attribute may only be applied to pointer-typed parameters. A pointer that
is dereferenceable can be loaded from speculatively without a risk of
trapping. The number of bytes known to be dereferenceable must be provided
in parentheses. It is legal for the number of bytes to be less than the
Expand All @@ -1584,7 +1584,7 @@ Currently, only the following parameter attributes are defined:
implies that a pointer is at least one of ``dereferenceable(<n>)``
or ``null`` (i.e., it may be both ``null`` and
``dereferenceable(<n>)``). This attribute may only be applied to
pointer typed parameters.
pointer-typed parameters.

``swiftself``
This indicates that the parameter is the self/context parameter. This is not
Expand All @@ -1601,7 +1601,7 @@ Currently, only the following parameter attributes are defined:

``swifterror``
This attribute is motivated to model and optimize Swift error handling. It
can be applied to a parameter with pointer to pointer type or a
can be applied to a parameter with pointer-to-pointer type or a
pointer-sized alloca. At the call site, the actual argument that corresponds
to a ``swifterror`` parameter has to come from a ``swifterror`` alloca or
the ``swifterror`` parameter of the caller. A ``swifterror`` value (either
Expand Down
4 changes: 4 additions & 0 deletions llvm/docs/ReleaseNotes.md
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,10 @@ Changes to the LLVM tools
* Some code paths for supporting Python 2.7 in `llvm-lit` have been removed.
* Support for `%T` in lit has been removed.

* `llvm-config` gained a new flag `--quote-paths` which quotes and escapes paths
emitted on stdout, to account for spaces or other special characters in path.
(`#97305 <https://github.com/llvm/llvm-project/pull/97305>`_).

Changes to LLDB
---------------------------------

Expand Down
2 changes: 1 addition & 1 deletion llvm/include/llvm/ADT/StringMap.h
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ class LLVM_ALLOCATORHOLDER_EMPTYBASE StringMap
if (FindInRHS == RHS.end())
return false;

if constexpr (!std::is_same_v<ValueTy, std::nullopt_t>) {
if constexpr (!std::is_same_v<ValueTy, EmptyStringSetTag>) {
if (!(KeyValue.getValue() == FindInRHS->getValue()))
return false;
}
Expand Down
10 changes: 6 additions & 4 deletions llvm/include/llvm/ADT/StringMapEntry.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@

namespace llvm {

/// The "value type" of StringSet represented as an empty struct.
struct EmptyStringSetTag {};

/// StringMapEntryBase - Shared base class of StringMapEntry instances.
class StringMapEntryBase {
size_t keyLength;
Expand Down Expand Up @@ -85,14 +88,13 @@ class StringMapEntryStorage : public StringMapEntryBase {
};

template <>
class StringMapEntryStorage<std::nullopt_t> : public StringMapEntryBase {
class StringMapEntryStorage<EmptyStringSetTag> : public StringMapEntryBase {
public:
explicit StringMapEntryStorage(size_t keyLength,
std::nullopt_t = std::nullopt)
explicit StringMapEntryStorage(size_t keyLength, EmptyStringSetTag = {})
: StringMapEntryBase(keyLength) {}
StringMapEntryStorage(StringMapEntryStorage &entry) = delete;

std::nullopt_t getValue() const { return std::nullopt; }
EmptyStringSetTag getValue() const { return {}; }
};

/// StringMapEntry - This is used to represent one value that is inserted into
Expand Down
Loading