Skip to content

Commit 49cd5f2

Browse files
author
Pavel V Chupin
committed
Merge commit '483efc9ad04dccd9f2163c84c2b6198ebb7049a6' into llvmspirv_pulldown
2 parents a4d7b9f + 483efc9 commit 49cd5f2

File tree

132 files changed

+5081
-2903
lines changed

Some content is hidden

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

132 files changed

+5081
-2903
lines changed

bolt/lib/Profile/DataReader.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ Optional<StringRef> getLTOCommonName(const StringRef Name) {
4747
return Name.substr(0, LTOSuffixPos + 10);
4848
if ((LTOSuffixPos = Name.find(".constprop.")) != StringRef::npos)
4949
return Name.substr(0, LTOSuffixPos + 11);
50+
if ((LTOSuffixPos = Name.find(".llvm.")) != StringRef::npos)
51+
return Name.substr(0, LTOSuffixPos + 6);
5052
return NoneType();
5153
}
5254

bolt/lib/Rewrite/DWARFRewriter.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -462,6 +462,7 @@ void DWARFRewriter::updateUnitDebugInfo(
462462
});
463463

464464
if (E || InputLL.empty()) {
465+
consumeError(std::move(E));
465466
errs() << "BOLT-WARNING: empty location list detected at 0x"
466467
<< Twine::utohexstr(Offset) << " for DIE at 0x"
467468
<< Twine::utohexstr(DIE.getOffset()) << " in CU at 0x"

bolt/test/X86/dwarf-handle-visit-loclist-error.s

Lines changed: 384 additions & 0 deletions
Large diffs are not rendered by default.

bolt/test/X86/lto-name-match.s

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
# REQUIRES: system-linux
2+
3+
# RUN: llvm-mc -filetype=obj -triple x86_64-unknown-unknown %s -o %t.o
4+
# RUN: link_fdata %s %t.o %t.fdata
5+
# RUN: llvm-strip --strip-unneeded %t.o
6+
# RUN: %clang %cflags %t.o -o %t.exe
7+
# RUN: llvm-bolt %t.exe -data %t.fdata -o /dev/null | FileCheck %s
8+
9+
## Check that profile is correctly matched by functions with variable suffixes.
10+
## E.g., LTO-generated name foo.llvm.123 should match foo.llvm.*.
11+
12+
# CHECK: 4 out of {{.*}} functions in the binary {{.*}} have non-empty execution profile
13+
# CHECK-NOT: profile for {{.*}} objects was ignored
14+
15+
.globl _start
16+
_start:
17+
18+
LL_start_0:
19+
# FDATA: 1 _start #LL_start_0# 1 foo.llvm.321 0 0 1
20+
call foo.llvm.123
21+
22+
LL_start_1:
23+
# FDATA: 1 _start #LL_start_1# 1 foo.constprop.321 0 0 1
24+
call foo.constprop.123
25+
26+
LL_start_2:
27+
# FDATA: 1 _start #LL_start_2# 1 foo.lto_priv.321 0 0 1
28+
call foo.lto_priv.123
29+
30+
call exit
31+
.size _start, .-_start
32+
33+
.globl foo.llvm.123
34+
.type foo.llvm.123,@function
35+
foo.llvm.123:
36+
ret
37+
.size foo.llvm.123, .-foo.llvm.123
38+
39+
.globl foo.constprop.123
40+
.type foo.constprop.123,@function
41+
foo.constprop.123:
42+
ret
43+
.size foo.constprop.123, .-foo.constprop.123
44+
45+
.globl foo.lto_priv.123
46+
.type foo.lto_priv.123,@function
47+
foo.lto_priv.123:
48+
ret
49+
.size foo.lto_priv.123, .-foo.lto_priv.123

clang/docs/CommandGuide/clang.rst

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -252,8 +252,24 @@ Language Selection and Mode Options
252252

253253
.. option:: -fno-builtin
254254

255-
Disable special handling and optimizations of builtin functions like
256-
:c:func:`strlen` and :c:func:`malloc`.
255+
Disable special handling and optimizations of well-known library functions,
256+
like :c:func:`strlen` and :c:func:`malloc`.
257+
258+
.. option:: -fno-builtin-<function>
259+
260+
Disable special handling and optimizations for the specific library function.
261+
For example, ``-fno-builtin-strlen`` removes any special handling for the
262+
:c:func:`strlen` library function.
263+
264+
.. option:: -fno-builtin-std-<function>
265+
266+
Disable special handling and optimizations for the specific C++ standard
267+
library function in namespace ``std``. For example,
268+
``-fno-builtin-std-move_if_noexcept`` removes any special handling for the
269+
:cpp:func:`std::move_if_noexcept` library function.
270+
271+
For C standard library functions that the C++ standard library also provides
272+
in namespace ``std``, use :option:`-fno-builtin-\<function\>` instead.
257273

258274
.. option:: -fmath-errno
259275

clang/docs/ReleaseNotes.rst

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,10 @@ C2x Feature Support
265265
C++ Language Changes in Clang
266266
-----------------------------
267267

268-
- ...
268+
- Improved ``-O0`` code generation for calls to ``std::move``, ``std::forward``,
269+
``std::move_if_noexcept``, ``std::addressof``, and ``std::as_const``. These
270+
are now treated as compiler builtins and implemented directly, rather than
271+
instantiating the definition from the standard library.
269272

270273
C++20 Feature Support
271274
^^^^^^^^^^^^^^^^^^^^^

clang/include/clang/Basic/Builtins.def

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,9 @@
8181
// builtin even if type doesn't match signature, and don't warn if we
8282
// can't be sure the type is right
8383
// F -> this is a libc/libm function with a '__builtin_' prefix added.
84-
// f -> this is a libc/libm function without the '__builtin_' prefix.
84+
// f -> this is a libc/libm function without a '__builtin_' prefix, or with
85+
// 'z', a C++ standard library function in namespace std::. This builtin
86+
// is disableable by '-fno-builtin-foo' / '-fno-builtin-std-foo'.
8587
// h -> this function requires a specific header or an explicit declaration.
8688
// i -> this is a runtime library implemented function without the
8789
// '__builtin_' prefix. It will be implemented in compiler-rt or libgcc.
@@ -101,6 +103,7 @@
101103
// V:N: -> requires vectors of at least N bits to be legal
102104
// C<N,M_0,...,M_k> -> callback behavior: argument N is called with argument
103105
// M_0, ..., M_k as payload
106+
// z -> this is a function in (possibly-versioned) namespace std
104107
// FIXME: gcc has nonnull
105108

106109
#if defined(BUILTIN) && !defined(LIBBUILTIN)
@@ -919,7 +922,7 @@ LANGBUILTIN(__exception_info, "v*", "n", ALL_MS_LANGUAGES)
919922
LANGBUILTIN(_exception_info, "v*", "n", ALL_MS_LANGUAGES)
920923
LANGBUILTIN(__abnormal_termination, "i", "n", ALL_MS_LANGUAGES)
921924
LANGBUILTIN(_abnormal_termination, "i", "n", ALL_MS_LANGUAGES)
922-
LANGBUILTIN(__GetExceptionInfo, "v*.", "ntu", ALL_MS_LANGUAGES)
925+
LANGBUILTIN(__GetExceptionInfo, "v*.", "zntu", ALL_MS_LANGUAGES)
923926
LANGBUILTIN(_InterlockedAnd8, "ccD*c", "n", ALL_MS_LANGUAGES)
924927
LANGBUILTIN(_InterlockedAnd16, "ssD*s", "n", ALL_MS_LANGUAGES)
925928
LANGBUILTIN(_InterlockedAnd, "NiNiD*Ni", "n", ALL_MS_LANGUAGES)
@@ -1543,6 +1546,15 @@ LIBBUILTIN(_Block_object_assign, "vv*vC*iC", "f", "Blocks.h", ALL_LANGUAGES)
15431546
LIBBUILTIN(_Block_object_dispose, "vvC*iC", "f", "Blocks.h", ALL_LANGUAGES)
15441547
// FIXME: Also declare NSConcreteGlobalBlock and NSConcreteStackBlock.
15451548

1549+
// C++ standard library builtins in namespace 'std'.
1550+
LIBBUILTIN(addressof, "v*v&", "zfncTh", "memory", CXX_LANG)
1551+
// Synonym for addressof used internally by libstdc++.
1552+
LANGBUILTIN(__addressof, "v*v&", "zfncT", CXX_LANG)
1553+
LIBBUILTIN(as_const, "v&v&", "zfncTh", "utility", CXX_LANG)
1554+
LIBBUILTIN(forward, "v&v&", "zfncTh", "utility", CXX_LANG)
1555+
LIBBUILTIN(move, "v&v&", "zfncTh", "utility", CXX_LANG)
1556+
LIBBUILTIN(move_if_noexcept, "v&v&", "zfncTh", "utility", CXX_LANG)
1557+
15461558
// Annotation function
15471559
BUILTIN(__builtin_annotation, "v.", "tn")
15481560

clang/include/clang/Basic/Builtins.h

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,10 @@ class Context {
138138
/// Determines whether this builtin is a predefined libc/libm
139139
/// function, such as "malloc", where we know the signature a
140140
/// priori.
141+
/// In C, such functions behave as if they are predeclared,
142+
/// possibly with a warning on first use. In Objective-C and C++,
143+
/// they do not, but they are recognized as builtins once we see
144+
/// a declaration.
141145
bool isPredefinedLibFunction(unsigned ID) const {
142146
return strchr(getRecord(ID).Attributes, 'f') != nullptr;
143147
}
@@ -156,6 +160,23 @@ class Context {
156160
return strchr(getRecord(ID).Attributes, 'i') != nullptr;
157161
}
158162

163+
/// Determines whether this builtin is a C++ standard library function
164+
/// that lives in (possibly-versioned) namespace std, possibly a template
165+
/// specialization, where the signature is determined by the standard library
166+
/// declaration.
167+
bool isInStdNamespace(unsigned ID) const {
168+
return strchr(getRecord(ID).Attributes, 'z') != nullptr;
169+
}
170+
171+
/// Determines whether this builtin can have its address taken with no
172+
/// special action required.
173+
bool isDirectlyAddressable(unsigned ID) const {
174+
// Most standard library functions can have their addresses taken. C++
175+
// standard library functions formally cannot in C++20 onwards, and when
176+
// we allow it, we need to ensure we instantiate a definition.
177+
return isPredefinedLibFunction(ID) && !isInStdNamespace(ID);
178+
}
179+
159180
/// Determines whether this builtin has custom typechecking.
160181
bool hasCustomTypechecking(unsigned ID) const {
161182
return strchr(getRecord(ID).Attributes, 't') != nullptr;
@@ -237,10 +258,6 @@ class Context {
237258
private:
238259
const Info &getRecord(unsigned ID) const;
239260

240-
/// Is this builtin supported according to the given language options?
241-
bool builtinIsSupported(const Builtin::Info &BuiltinInfo,
242-
const LangOptions &LangOpts);
243-
244261
/// Helper function for isPrintfLike and isScanfLike.
245262
bool isLike(unsigned ID, unsigned &FormatIdx, bool &HasVAListArg,
246263
const char *Fmt) const;

clang/include/clang/Basic/DiagnosticSemaKinds.td

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6638,6 +6638,15 @@ def warn_self_move : Warning<
66386638
"explicitly moving variable of type %0 to itself">,
66396639
InGroup<SelfMove>, DefaultIgnore;
66406640

6641+
def err_builtin_move_forward_unsupported : Error<
6642+
"unsupported signature for %q0">;
6643+
def err_use_of_unaddressable_function : Error<
6644+
"taking address of non-addressable standard library function">;
6645+
// FIXME: This should also be in -Wc++23-compat once we have it.
6646+
def warn_cxx20_compat_use_of_unaddressable_function : Warning<
6647+
"taking address of non-addressable standard library function "
6648+
"is incompatible with C++20">, InGroup<CXX20Compat>;
6649+
66416650
def warn_redundant_move_on_return : Warning<
66426651
"redundant move in return statement">,
66436652
InGroup<RedundantMove>, DefaultIgnore;

clang/lib/AST/ExprConstant.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8127,6 +8127,7 @@ class LValueExprEvaluator
81278127
bool VisitVarDecl(const Expr *E, const VarDecl *VD);
81288128
bool VisitUnaryPreIncDec(const UnaryOperator *UO);
81298129

8130+
bool VisitCallExpr(const CallExpr *E);
81308131
bool VisitDeclRefExpr(const DeclRefExpr *E);
81318132
bool VisitPredefinedExpr(const PredefinedExpr *E) { return Success(E); }
81328133
bool VisitMaterializeTemporaryExpr(const MaterializeTemporaryExpr *E);
@@ -8292,6 +8293,20 @@ bool LValueExprEvaluator::VisitVarDecl(const Expr *E, const VarDecl *VD) {
82928293
return Success(*V, E);
82938294
}
82948295

8296+
bool LValueExprEvaluator::VisitCallExpr(const CallExpr *E) {
8297+
switch (E->getBuiltinCallee()) {
8298+
case Builtin::BIas_const:
8299+
case Builtin::BIforward:
8300+
case Builtin::BImove:
8301+
case Builtin::BImove_if_noexcept:
8302+
if (cast<FunctionDecl>(E->getCalleeDecl())->isConstexpr())
8303+
return Visit(E->getArg(0));
8304+
break;
8305+
}
8306+
8307+
return ExprEvaluatorBaseTy::VisitCallExpr(E);
8308+
}
8309+
82958310
bool LValueExprEvaluator::VisitMaterializeTemporaryExpr(
82968311
const MaterializeTemporaryExpr *E) {
82978312
// Walk through the expression to find the materialized temporary itself.
@@ -9088,6 +9103,8 @@ static bool isOneByteCharacterType(QualType T) {
90889103
bool PointerExprEvaluator::VisitBuiltinCallExpr(const CallExpr *E,
90899104
unsigned BuiltinOp) {
90909105
switch (BuiltinOp) {
9106+
case Builtin::BIaddressof:
9107+
case Builtin::BI__addressof:
90919108
case Builtin::BI__builtin_addressof:
90929109
return evaluateLValue(E->getArg(0), Result);
90939110
case Builtin::BI__builtin_assume_aligned: {

0 commit comments

Comments
 (0)