Skip to content

Commit e75d8b7

Browse files
committed
Revert "Treat std::move, forward, and move_if_noexcept as builtins."
Revert "Extend support for std::move etc to also cover std::as_const and" Revert "Update test to handle opaque pointers flag flip." It crashes on libcxx tests https://lab.llvm.org/buildbot/#/builders/85/builds/8174 This reverts commit fc30901. This reverts commit a571f82. This reverts commit 64c045e.
1 parent 7098687 commit e75d8b7

28 files changed

+78
-540
lines changed

clang/docs/CommandGuide/clang.rst

+2-18
Original file line numberDiff line numberDiff line change
@@ -252,24 +252,8 @@ Language Selection and Mode Options
252252

253253
.. option:: -fno-builtin
254254

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.
255+
Disable special handling and optimizations of builtin functions like
256+
:c:func:`strlen` and :c:func:`malloc`.
273257

274258
.. option:: -fmath-errno
275259

clang/docs/ReleaseNotes.rst

+1-4
Original file line numberDiff line numberDiff line change
@@ -230,10 +230,7 @@ C2x Feature Support
230230
C++ Language Changes in Clang
231231
-----------------------------
232232

233-
- Improved ``-O0`` code generation for calls to ``std::move``, ``std::forward``,
234-
and ``std::move_if_noexcept``. These are now treated as compiler builtins and
235-
implemented directly, rather than instantiating the definition from the
236-
standard library.
233+
- ...
237234

238235
C++20 Feature Support
239236
^^^^^^^^^^^^^^^^^^^^^

clang/include/clang/Basic/Builtins.def

+2-14
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,7 @@
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 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'.
84+
// f -> this is a libc/libm function without the '__builtin_' prefix.
8785
// h -> this function requires a specific header or an explicit declaration.
8886
// i -> this is a runtime library implemented function without the
8987
// '__builtin_' prefix. It will be implemented in compiler-rt or libgcc.
@@ -103,7 +101,6 @@
103101
// V:N: -> requires vectors of at least N bits to be legal
104102
// C<N,M_0,...,M_k> -> callback behavior: argument N is called with argument
105103
// M_0, ..., M_k as payload
106-
// z -> this is a function in (possibly-versioned) namespace std
107104
// FIXME: gcc has nonnull
108105

109106
#if defined(BUILTIN) && !defined(LIBBUILTIN)
@@ -922,7 +919,7 @@ LANGBUILTIN(__exception_info, "v*", "n", ALL_MS_LANGUAGES)
922919
LANGBUILTIN(_exception_info, "v*", "n", ALL_MS_LANGUAGES)
923920
LANGBUILTIN(__abnormal_termination, "i", "n", ALL_MS_LANGUAGES)
924921
LANGBUILTIN(_abnormal_termination, "i", "n", ALL_MS_LANGUAGES)
925-
LANGBUILTIN(__GetExceptionInfo, "v*.", "zntu", ALL_MS_LANGUAGES)
922+
LANGBUILTIN(__GetExceptionInfo, "v*.", "ntu", ALL_MS_LANGUAGES)
926923
LANGBUILTIN(_InterlockedAnd8, "ccD*c", "n", ALL_MS_LANGUAGES)
927924
LANGBUILTIN(_InterlockedAnd16, "ssD*s", "n", ALL_MS_LANGUAGES)
928925
LANGBUILTIN(_InterlockedAnd, "NiNiD*Ni", "n", ALL_MS_LANGUAGES)
@@ -1546,15 +1543,6 @@ LIBBUILTIN(_Block_object_assign, "vv*vC*iC", "f", "Blocks.h", ALL_LANGUAGES)
15461543
LIBBUILTIN(_Block_object_dispose, "vvC*iC", "f", "Blocks.h", ALL_LANGUAGES)
15471544
// FIXME: Also declare NSConcreteGlobalBlock and NSConcreteStackBlock.
15481545

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-
15581546
// Annotation function
15591547
BUILTIN(__builtin_annotation, "v.", "tn")
15601548

clang/include/clang/Basic/Builtins.h

+4-21
Original file line numberDiff line numberDiff line change
@@ -138,10 +138,6 @@ 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.
145141
bool isPredefinedLibFunction(unsigned ID) const {
146142
return strchr(getRecord(ID).Attributes, 'f') != nullptr;
147143
}
@@ -160,23 +156,6 @@ class Context {
160156
return strchr(getRecord(ID).Attributes, 'i') != nullptr;
161157
}
162158

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-
180159
/// Determines whether this builtin has custom typechecking.
181160
bool hasCustomTypechecking(unsigned ID) const {
182161
return strchr(getRecord(ID).Attributes, 't') != nullptr;
@@ -258,6 +237,10 @@ class Context {
258237
private:
259238
const Info &getRecord(unsigned ID) const;
260239

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

clang/include/clang/Basic/DiagnosticSemaKinds.td

-9
Original file line numberDiff line numberDiff line change
@@ -6586,15 +6586,6 @@ def warn_self_move : Warning<
65866586
"explicitly moving variable of type %0 to itself">,
65876587
InGroup<SelfMove>, DefaultIgnore;
65886588

6589-
def err_builtin_move_forward_unsupported : Error<
6590-
"unsupported signature for %q0">;
6591-
def err_use_of_unaddressable_function : Error<
6592-
"taking address of non-addressable standard library function">;
6593-
// FIXME: This should also be in -Wc++23-compat once we have it.
6594-
def warn_cxx20_compat_use_of_unaddressable_function : Warning<
6595-
"taking address of non-addressable standard library function "
6596-
"is incompatible with C++20">, InGroup<CXX20Compat>;
6597-
65986589
def warn_redundant_move_on_return : Warning<
65996590
"redundant move in return statement">,
66006591
InGroup<RedundantMove>, DefaultIgnore;

clang/lib/AST/ExprConstant.cpp

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

8130-
bool VisitCallExpr(const CallExpr *E);
81318130
bool VisitDeclRefExpr(const DeclRefExpr *E);
81328131
bool VisitPredefinedExpr(const PredefinedExpr *E) { return Success(E); }
81338132
bool VisitMaterializeTemporaryExpr(const MaterializeTemporaryExpr *E);
@@ -8293,20 +8292,6 @@ bool LValueExprEvaluator::VisitVarDecl(const Expr *E, const VarDecl *VD) {
82938292
return Success(*V, E);
82948293
}
82958294

8296-
bool LValueExprEvaluator::VisitCallExpr(const CallExpr *E) {
8297-
switch (unsigned BuiltinOp = 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-
83108295
bool LValueExprEvaluator::VisitMaterializeTemporaryExpr(
83118296
const MaterializeTemporaryExpr *E) {
83128297
// Walk through the expression to find the materialized temporary itself.
@@ -9085,8 +9070,6 @@ static bool isOneByteCharacterType(QualType T) {
90859070
bool PointerExprEvaluator::VisitBuiltinCallExpr(const CallExpr *E,
90869071
unsigned BuiltinOp) {
90879072
switch (BuiltinOp) {
9088-
case Builtin::BIaddressof:
9089-
case Builtin::BI__addressof:
90909073
case Builtin::BI__builtin_addressof:
90919074
return evaluateLValue(E->getArg(0), Result);
90929075
case Builtin::BI__builtin_assume_aligned: {

clang/lib/Analysis/BodyFarm.cpp

+2-44
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
#include "clang/AST/ExprObjC.h"
2121
#include "clang/AST/NestedNameSpecifier.h"
2222
#include "clang/Analysis/CodeInjector.h"
23-
#include "clang/Basic/Builtins.h"
2423
#include "clang/Basic/OperatorKinds.h"
2524
#include "llvm/ADT/StringSwitch.h"
2625
#include "llvm/Support/Debug.h"
@@ -87,9 +86,6 @@ class ASTMaker {
8786
ImplicitCastExpr *makeImplicitCast(const Expr *Arg, QualType Ty,
8887
CastKind CK = CK_LValueToRValue);
8988

90-
/// Create a cast to reference type.
91-
CastExpr *makeReferenceCast(const Expr *Arg, QualType Ty);
92-
9389
/// Create an Objective-C bool literal.
9490
ObjCBoolLiteralExpr *makeObjCBool(bool Val);
9591

@@ -177,16 +173,6 @@ ImplicitCastExpr *ASTMaker::makeImplicitCast(const Expr *Arg, QualType Ty,
177173
/* FPFeatures */ FPOptionsOverride());
178174
}
179175

180-
CastExpr *ASTMaker::makeReferenceCast(const Expr *Arg, QualType Ty) {
181-
assert(Ty->isReferenceType());
182-
return CXXStaticCastExpr::Create(
183-
C, Ty.getNonReferenceType(),
184-
Ty->isLValueReferenceType() ? VK_LValue : VK_XValue, CK_NoOp,
185-
const_cast<Expr *>(Arg), /*CXXCastPath=*/nullptr,
186-
/*Written=*/C.getTrivialTypeSourceInfo(Ty), FPOptionsOverride(),
187-
SourceLocation(), SourceLocation(), SourceRange());
188-
}
189-
190176
Expr *ASTMaker::makeIntegralCast(const Expr *Arg, QualType Ty) {
191177
if (Arg->getType() == Ty)
192178
return const_cast<Expr*>(Arg);
@@ -310,22 +296,6 @@ static CallExpr *create_call_once_lambda_call(ASTContext &C, ASTMaker M,
310296
/*FPFeatures=*/FPOptionsOverride());
311297
}
312298

313-
/// Create a fake body for 'std::move' or 'std::forward'. This is just:
314-
///
315-
/// \code
316-
/// return static_cast<return_type>(param);
317-
/// \endcode
318-
static Stmt *create_std_move_forward(ASTContext &C, const FunctionDecl *D) {
319-
LLVM_DEBUG(llvm::dbgs() << "Generating body for std::move / std::forward\n");
320-
321-
ASTMaker M(C);
322-
323-
QualType ReturnType = D->getType()->castAs<FunctionType>()->getReturnType();
324-
Expr *Param = M.makeDeclRefExpr(D->getParamDecl(0));
325-
Expr *Cast = M.makeReferenceCast(Param, ReturnType);
326-
return M.makeReturn(Cast);
327-
}
328-
329299
/// Create a fake body for std::call_once.
330300
/// Emulates the following function body:
331301
///
@@ -711,20 +681,8 @@ Stmt *BodyFarm::getBody(const FunctionDecl *D) {
711681

712682
FunctionFarmer FF;
713683

714-
if (unsigned BuiltinID = D->getBuiltinID()) {
715-
switch (BuiltinID) {
716-
case Builtin::BIas_const:
717-
case Builtin::BIforward:
718-
case Builtin::BImove:
719-
case Builtin::BImove_if_noexcept:
720-
FF = create_std_move_forward;
721-
break;
722-
default:
723-
FF = nullptr;
724-
break;
725-
}
726-
} else if (Name.startswith("OSAtomicCompareAndSwap") ||
727-
Name.startswith("objc_atomicCompareAndSwap")) {
684+
if (Name.startswith("OSAtomicCompareAndSwap") ||
685+
Name.startswith("objc_atomicCompareAndSwap")) {
728686
FF = create_OSAtomicCompareAndSwap;
729687
} else if (Name == "call_once" && D->getDeclContext()->isStdNamespace()) {
730688
FF = create_call_once;

clang/lib/Basic/Builtins.cpp

+10-26
Original file line numberDiff line numberDiff line change
@@ -48,22 +48,18 @@ void Builtin::Context::InitializeTarget(const TargetInfo &Target,
4848
}
4949

5050
bool Builtin::Context::isBuiltinFunc(llvm::StringRef FuncName) {
51-
bool InStdNamespace = FuncName.consume_front("std-");
52-
for (unsigned i = Builtin::NotBuiltin + 1; i != Builtin::FirstTSBuiltin;
53-
++i) {
54-
if (FuncName.equals(BuiltinInfo[i].Name) &&
55-
(bool)strchr(BuiltinInfo[i].Attributes, 'z') == InStdNamespace)
51+
for (unsigned i = Builtin::NotBuiltin + 1; i != Builtin::FirstTSBuiltin; ++i)
52+
if (FuncName.equals(BuiltinInfo[i].Name))
5653
return strchr(BuiltinInfo[i].Attributes, 'f') != nullptr;
57-
}
5854

5955
return false;
6056
}
6157

62-
/// Is this builtin supported according to the given language options?
63-
static bool builtinIsSupported(const Builtin::Info &BuiltinInfo,
64-
const LangOptions &LangOpts) {
58+
bool Builtin::Context::builtinIsSupported(const Builtin::Info &BuiltinInfo,
59+
const LangOptions &LangOpts) {
6560
bool BuiltinsUnsupported =
66-
LangOpts.NoBuiltin && strchr(BuiltinInfo.Attributes, 'f') != nullptr;
61+
(LangOpts.NoBuiltin || LangOpts.isNoBuiltinFunc(BuiltinInfo.Name)) &&
62+
strchr(BuiltinInfo.Attributes, 'f');
6763
bool CorBuiltinsUnsupported =
6864
!LangOpts.Coroutines && (BuiltinInfo.Langs & COR_LANG);
6965
bool MathBuiltinsUnsupported =
@@ -115,19 +111,6 @@ void Builtin::Context::initializeBuiltins(IdentifierTable &Table,
115111
for (unsigned i = 0, e = AuxTSRecords.size(); i != e; ++i)
116112
Table.get(AuxTSRecords[i].Name)
117113
.setBuiltinID(i + Builtin::FirstTSBuiltin + TSRecords.size());
118-
119-
// Step #4: Unregister any builtins specified by -fno-builtin-foo.
120-
for (llvm::StringRef Name : LangOpts.NoBuiltinFuncs) {
121-
bool InStdNamespace = Name.consume_front("std-");
122-
auto NameIt = Table.find(Name);
123-
if (NameIt != Table.end()) {
124-
unsigned ID = NameIt->second->getBuiltinID();
125-
if (ID != Builtin::NotBuiltin && isPredefinedLibFunction(ID) &&
126-
isInStdNamespace(ID) == InStdNamespace) {
127-
Table.get(Name).setBuiltinID(Builtin::NotBuiltin);
128-
}
129-
}
130-
}
131114
}
132115

133116
unsigned Builtin::Context::getRequiredVectorWidth(unsigned ID) const {
@@ -207,7 +190,8 @@ bool Builtin::Context::performsCallback(unsigned ID,
207190
}
208191

209192
bool Builtin::Context::canBeRedeclared(unsigned ID) const {
210-
return ID == Builtin::NotBuiltin || ID == Builtin::BI__va_start ||
211-
(!hasReferenceArgsOrResult(ID) && !hasCustomTypechecking(ID)) ||
212-
isInStdNamespace(ID);
193+
return ID == Builtin::NotBuiltin ||
194+
ID == Builtin::BI__va_start ||
195+
(!hasReferenceArgsOrResult(ID) &&
196+
!hasCustomTypechecking(ID));
213197
}

clang/lib/CodeGen/CGBuiltin.cpp

-8
Original file line numberDiff line numberDiff line change
@@ -4566,8 +4566,6 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl GD, unsigned BuiltinID,
45664566

45674567
return RValue::get(Carry);
45684568
}
4569-
case Builtin::BIaddressof:
4570-
case Builtin::BI__addressof:
45714569
case Builtin::BI__builtin_addressof:
45724570
return RValue::get(EmitLValue(E->getArg(0)).getPointer(*this));
45734571
case Builtin::BI__builtin_function_start:
@@ -4727,12 +4725,6 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl GD, unsigned BuiltinID,
47274725
}
47284726
break;
47294727

4730-
// C++ std:: builtins.
4731-
case Builtin::BImove:
4732-
case Builtin::BImove_if_noexcept:
4733-
case Builtin::BIforward:
4734-
case Builtin::BIas_const:
4735-
return RValue::get(EmitLValue(E->getArg(0)).getPointer(*this));
47364728
case Builtin::BI__GetExceptionInfo: {
47374729
if (llvm::GlobalVariable *GV =
47384730
CGM.getCXXABI().getThrowInfo(FD->getParamDecl(0)->getType()))

clang/lib/CodeGen/CGCall.cpp

-2
Original file line numberDiff line numberDiff line change
@@ -1805,8 +1805,6 @@ void CodeGenModule::getDefaultFunctionAttributes(StringRef Name,
18051805

18061806
if (AttrOnCallSite) {
18071807
// Attributes that should go on the call site only.
1808-
// FIXME: Look for 'BuiltinAttr' on the function rather than re-checking
1809-
// the -fno-builtin-foo list.
18101808
if (!CodeGenOpts.SimplifyLibCalls || LangOpts.isNoBuiltinFunc(Name))
18111809
FuncAttrs.addAttribute(llvm::Attribute::NoBuiltin);
18121810
if (!CodeGenOpts.TrapFuncName.empty())

clang/lib/Sema/SemaChecking.cpp

-26
Original file line numberDiff line numberDiff line change
@@ -2130,32 +2130,6 @@ Sema::CheckBuiltinFunctionCall(FunctionDecl *FDecl, unsigned BuiltinID,
21302130

21312131
TheCall->setType(Context.VoidPtrTy);
21322132
break;
2133-
case Builtin::BIaddressof:
2134-
case Builtin::BI__addressof:
2135-
case Builtin::BIforward:
2136-
case Builtin::BImove:
2137-
case Builtin::BImove_if_noexcept:
2138-
case Builtin::BIas_const: {
2139-
// These are all expected to be of the form
2140-
// T &/&&/* f(U &/&&)
2141-
// where T and U only differ in qualification.
2142-
if (checkArgCount(*this, TheCall, 1))
2143-
return ExprError();
2144-
QualType Param = FDecl->getParamDecl(0)->getType();
2145-
QualType Result = FDecl->getReturnType();
2146-
bool ReturnsPointer = BuiltinID == Builtin::BIaddressof ||
2147-
BuiltinID == Builtin::BI__addressof;
2148-
if (!(Param->isReferenceType() &&
2149-
(ReturnsPointer ? Result->isPointerType()
2150-
: Result->isReferenceType()) &&
2151-
Context.hasSameUnqualifiedType(Param->getPointeeType(),
2152-
Result->getPointeeType()))) {
2153-
Diag(TheCall->getBeginLoc(), diag::err_builtin_move_forward_unsupported)
2154-
<< FDecl;
2155-
return ExprError();
2156-
}
2157-
break;
2158-
}
21592133
// OpenCL v2.0, s6.13.16 - Pipe functions
21602134
case Builtin::BIread_pipe:
21612135
case Builtin::BIwrite_pipe:

0 commit comments

Comments
 (0)