Skip to content

Commit 634fc82

Browse files
committed
Merge remote-tracking branch 'origin/apple/stable/20200714' into swift/main
2 parents 41be35f + 58e662c commit 634fc82

Some content is hidden

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

46 files changed

+965
-285
lines changed

clang/include/clang/Basic/Attr.td

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3594,3 +3594,11 @@ def ReleaseHandle : InheritableParamAttr {
35943594
let Subjects = SubjectList<[ParmVar]>;
35953595
let Documentation = [ReleaseHandleDocs];
35963596
}
3597+
3598+
def Builtin : InheritableAttr {
3599+
let Spellings = [];
3600+
let Args = [UnsignedArgument<"ID">];
3601+
let Subjects = SubjectList<[Function]>;
3602+
let SemaHandler = 0;
3603+
let Documentation = [Undocumented];
3604+
}

clang/include/clang/Basic/Builtins.def

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,9 @@
7575
// U -> pure
7676
// c -> const
7777
// t -> signature is meaningless, use custom typechecking
78+
// T -> type is not important to semantic analysis and codegen; recognize as
79+
// builtin even if type doesn't match signature, and don't warn if we
80+
// can't be sure the type is right
7881
// F -> this is a libc/libm function with a '__builtin_' prefix added.
7982
// f -> this is a libc/libm function without the '__builtin_' prefix. It can
8083
// be followed by ':headername:' to state which header this function
@@ -893,7 +896,7 @@ LANGBUILTIN(__va_start, "vc**.", "nt", ALL_MS_LANGUAGES)
893896
LANGBUILTIN(__fastfail, "vUi", "nr", ALL_MS_LANGUAGES)
894897

895898
// Microsoft library builtins.
896-
LIBBUILTIN(_setjmpex, "iJ", "fj", "setjmpex.h", ALL_MS_LANGUAGES)
899+
LIBBUILTIN(_setjmpex, "iJ", "fjT", "setjmpex.h", ALL_MS_LANGUAGES)
897900

898901
// C99 library functions
899902
// C99 stdarg.h
@@ -987,8 +990,8 @@ LIBBUILTIN(wmemmove,"w*w*wC*z", "f", "wchar.h", ALL_LANGUAGES)
987990
// In some systems setjmp is a macro that expands to _setjmp. We undefine
988991
// it here to avoid having two identical LIBBUILTIN entries.
989992
#undef setjmp
990-
LIBBUILTIN(setjmp, "iJ", "fj", "setjmp.h", ALL_LANGUAGES)
991-
LIBBUILTIN(longjmp, "vJi", "fr", "setjmp.h", ALL_LANGUAGES)
993+
LIBBUILTIN(setjmp, "iJ", "fjT", "setjmp.h", ALL_LANGUAGES)
994+
LIBBUILTIN(longjmp, "vJi", "frT", "setjmp.h", ALL_LANGUAGES)
992995

993996
// Non-C library functions, active in GNU mode only.
994997
// Functions with (returns_twice) attribute (marked as "j") are still active in
@@ -1015,20 +1018,22 @@ LIBBUILTIN(strcasecmp, "icC*cC*", "f", "strings.h", ALL_GNU_LANGUAGES)
10151018
LIBBUILTIN(strncasecmp, "icC*cC*z", "f", "strings.h", ALL_GNU_LANGUAGES)
10161019
// POSIX unistd.h
10171020
LIBBUILTIN(_exit, "vi", "fr", "unistd.h", ALL_GNU_LANGUAGES)
1018-
LIBBUILTIN(vfork, "p", "fj", "unistd.h", ALL_LANGUAGES)
1021+
LIBBUILTIN(vfork, "p", "fjT", "unistd.h", ALL_LANGUAGES)
10191022
// POSIX pthread.h
1023+
// FIXME: Should specify argument types.
10201024
LIBBUILTIN(pthread_create, "", "fC<2,3>", "pthread.h", ALL_GNU_LANGUAGES)
10211025

10221026
// POSIX setjmp.h
10231027

1024-
LIBBUILTIN(_setjmp, "iJ", "fj", "setjmp.h", ALL_LANGUAGES)
1025-
LIBBUILTIN(__sigsetjmp, "iSJi", "fj", "setjmp.h", ALL_LANGUAGES)
1026-
LIBBUILTIN(sigsetjmp, "iSJi", "fj", "setjmp.h", ALL_LANGUAGES)
1027-
LIBBUILTIN(savectx, "iJ", "fj", "setjmp.h", ALL_LANGUAGES)
1028-
LIBBUILTIN(getcontext, "iK*", "fj", "setjmp.h", ALL_LANGUAGES)
1028+
// FIXME: MinGW _setjmp has an additional void* parameter.
1029+
LIBBUILTIN(_setjmp, "iJ", "fjT", "setjmp.h", ALL_LANGUAGES)
1030+
LIBBUILTIN(__sigsetjmp, "iSJi", "fjT", "setjmp.h", ALL_LANGUAGES)
1031+
LIBBUILTIN(sigsetjmp, "iSJi", "fjT", "setjmp.h", ALL_LANGUAGES)
1032+
LIBBUILTIN(savectx, "iJ", "fjT", "setjmp.h", ALL_LANGUAGES)
1033+
LIBBUILTIN(getcontext, "iK*", "fjT", "setjmp.h", ALL_LANGUAGES)
10291034

1030-
LIBBUILTIN(_longjmp, "vJi", "fr", "setjmp.h", ALL_GNU_LANGUAGES)
1031-
LIBBUILTIN(siglongjmp, "vSJi", "fr", "setjmp.h", ALL_GNU_LANGUAGES)
1035+
LIBBUILTIN(_longjmp, "vJi", "frT", "setjmp.h", ALL_GNU_LANGUAGES)
1036+
LIBBUILTIN(siglongjmp, "vSJi", "frT", "setjmp.h", ALL_GNU_LANGUAGES)
10321037
// non-standard but very common
10331038
LIBBUILTIN(strlcpy, "zc*cC*z", "f", "string.h", ALL_GNU_LANGUAGES)
10341039
LIBBUILTIN(strlcat, "zc*cC*z", "f", "string.h", ALL_GNU_LANGUAGES)

clang/include/clang/Basic/Builtins.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,13 @@ class Context {
158158
return strchr(getRecord(ID).Attributes, 't') != nullptr;
159159
}
160160

161+
/// Determines whether a declaration of this builtin should be recognized
162+
/// even if the type doesn't match the specified signature.
163+
bool allowTypeMismatch(unsigned ID) const {
164+
return strchr(getRecord(ID).Attributes, 'T') != nullptr ||
165+
hasCustomTypechecking(ID);
166+
}
167+
161168
/// Determines whether this builtin has a result or any arguments which
162169
/// are pointer types.
163170
bool hasPtrArgsOrResult(unsigned ID) const {

clang/include/clang/Basic/IdentifierTable.h

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -221,18 +221,6 @@ class alignas(IdentifierInfoAlignment) IdentifierInfo {
221221
}
222222
void setObjCKeywordID(tok::ObjCKeywordKind ID) { ObjCOrBuiltinID = ID; }
223223

224-
/// True if setNotBuiltin() was called.
225-
bool hasRevertedBuiltin() const {
226-
return ObjCOrBuiltinID == tok::NUM_OBJC_KEYWORDS;
227-
}
228-
229-
/// Revert the identifier to a non-builtin identifier. We do this if
230-
/// the name of a known builtin library function is used to declare that
231-
/// function, but an unexpected type is specified.
232-
void revertBuiltin() {
233-
setBuiltinID(0);
234-
}
235-
236224
/// Return a value indicating whether this is a builtin function.
237225
///
238226
/// 0 is not-built-in. 1+ are specific builtin functions.

clang/include/clang/Sema/Sema.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3990,6 +3990,8 @@ class Sema final {
39903990
ObjCInterfaceDecl *getObjCInterfaceDecl(IdentifierInfo *&Id,
39913991
SourceLocation IdLoc,
39923992
bool TypoCorrection = false);
3993+
FunctionDecl *CreateBuiltin(IdentifierInfo *II, QualType Type, unsigned ID,
3994+
SourceLocation Loc);
39933995
NamedDecl *LazilyCreateBuiltin(IdentifierInfo *II, unsigned ID,
39943996
Scope *S, bool ForRedeclaration,
39953997
SourceLocation Loc);

clang/lib/AST/Decl.cpp

Lines changed: 4 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -3163,44 +3163,24 @@ FunctionDecl *FunctionDecl::getCanonicalDecl() { return getFirstDecl(); }
31633163
/// functions as their wrapped builtins. This shouldn't be done in general, but
31643164
/// it's useful in Sema to diagnose calls to wrappers based on their semantics.
31653165
unsigned FunctionDecl::getBuiltinID(bool ConsiderWrapperFunctions) const {
3166-
unsigned BuiltinID;
3166+
unsigned BuiltinID = 0;
31673167

31683168
if (const auto *ABAA = getAttr<ArmBuiltinAliasAttr>()) {
31693169
BuiltinID = ABAA->getBuiltinName()->getBuiltinID();
3170-
} else {
3171-
if (!getIdentifier())
3172-
return 0;
3173-
3174-
BuiltinID = getIdentifier()->getBuiltinID();
3170+
} else if (const auto *A = getAttr<BuiltinAttr>()) {
3171+
BuiltinID = A->getID();
31753172
}
31763173

31773174
if (!BuiltinID)
31783175
return 0;
31793176

3180-
ASTContext &Context = getASTContext();
3181-
if (Context.getLangOpts().CPlusPlus) {
3182-
const auto *LinkageDecl =
3183-
dyn_cast<LinkageSpecDecl>(getFirstDecl()->getDeclContext());
3184-
// In C++, the first declaration of a builtin is always inside an implicit
3185-
// extern "C".
3186-
// FIXME: A recognised library function may not be directly in an extern "C"
3187-
// declaration, for instance "extern "C" { namespace std { decl } }".
3188-
if (!LinkageDecl) {
3189-
if (BuiltinID == Builtin::BI__GetExceptionInfo &&
3190-
Context.getTargetInfo().getCXXABI().isMicrosoft())
3191-
return Builtin::BI__GetExceptionInfo;
3192-
return 0;
3193-
}
3194-
if (LinkageDecl->getLanguage() != LinkageSpecDecl::lang_c)
3195-
return 0;
3196-
}
3197-
31983177
// If the function is marked "overloadable", it has a different mangled name
31993178
// and is not the C library function.
32003179
if (!ConsiderWrapperFunctions && hasAttr<OverloadableAttr>() &&
32013180
!hasAttr<ArmBuiltinAliasAttr>())
32023181
return 0;
32033182

3183+
ASTContext &Context = getASTContext();
32043184
if (!Context.BuiltinInfo.isPredefinedLibFunction(BuiltinID))
32053185
return BuiltinID;
32063186

clang/lib/CodeGen/CGBuiltin.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3827,11 +3827,13 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl GD, unsigned BuiltinID,
38273827
case Builtin::BI_abnormal_termination:
38283828
return RValue::get(EmitSEHAbnormalTermination());
38293829
case Builtin::BI_setjmpex:
3830-
if (getTarget().getTriple().isOSMSVCRT())
3830+
if (getTarget().getTriple().isOSMSVCRT() && E->getNumArgs() == 1 &&
3831+
E->getArg(0)->getType()->isPointerType())
38313832
return EmitMSVCRTSetJmp(*this, MSVCSetJmpKind::_setjmpex, E);
38323833
break;
38333834
case Builtin::BI_setjmp:
3834-
if (getTarget().getTriple().isOSMSVCRT()) {
3835+
if (getTarget().getTriple().isOSMSVCRT() && E->getNumArgs() == 1 &&
3836+
E->getArg(0)->getType()->isPointerType()) {
38353837
if (getTarget().getTriple().getArch() == llvm::Triple::x86)
38363838
return EmitMSVCRTSetJmp(*this, MSVCSetJmpKind::_setjmp3, E);
38373839
else if (getTarget().getTriple().getArch() == llvm::Triple::aarch64)

0 commit comments

Comments
 (0)