Commit ad531fff authored by Vlad Tsyrklevich's avatar Vlad Tsyrklevich
Browse files

Revert "[clang] Add no_builtin attribute"

This reverts commit bd879161. It was
causing ASan/MSan failures on the sanitizer buildbots.
parent 2513250b
Loading
Loading
Loading
Loading
+0 −4
Original line number Diff line number Diff line
@@ -2031,10 +2031,6 @@ public:
  ///
  /// This does not determine whether the function has been defined (e.g., in a
  /// previous definition); for that information, use isDefined.
  ///
  /// Note: the function declaration does not become a definition until the
  /// parser reaches the definition, if called before, this function will return
  /// `false`.
  bool isThisDeclarationADefinition() const {
    return isDeletedAsWritten() || isDefaulted() || Body || hasSkippedBody() ||
           isLateTemplateParsed() || willHaveBody() || hasDefiningAttr();
+0 −7
Original line number Diff line number Diff line
@@ -3427,10 +3427,3 @@ def ObjCExternallyRetained : InheritableAttr {
  let Subjects = SubjectList<[NonParmVar, Function, Block, ObjCMethod]>;
  let Documentation = [ObjCExternallyRetainedDocs];
}

def NoBuiltin : Attr {
  let Spellings = [Clang<"no_builtin">];
  let Args = [VariadicStringArgument<"BuiltinNames">];
  let Subjects = SubjectList<[Function]>;
  let Documentation = [NoBuiltinDocs];
}
+0 −37
Original line number Diff line number Diff line
@@ -4413,40 +4413,3 @@ and is not a general mechanism for declaring arbitrary aliases for
clang builtin functions.
  }];
}

def NoBuiltinDocs : Documentation {
  let Category = DocCatFunction;
  let Content = [{
.. Note:: This attribute is not yet fully implemented, it is validated but has
no effect on the generated code.

The ``__attribute__((no_builtin))`` is similar to the ``-fno-builtin`` flag
except it is specific to the body of a function. The attribute may also be
applied to a virtual function but has no effect on the behavior of overriding
functions in a derived class.

It accepts one or more strings corresponding to the specific names of the
builtins to disable (e.g. "memcpy", "memset").
If the attribute is used without parameters it will disable all buitins at
once.

.. code-block:: c++

  // The compiler is not allowed to add any builtin to foo's body.
  void foo(char* data, size_t count) __attribute__((no_builtin)) {
    // The compiler is not allowed to convert the loop into
    // `__builtin_memset(data, 0xFE, count);`.
    for (size_t i = 0; i < count; ++i)
      data[i] = 0xFE;
  }

  // The compiler is not allowed to add the `memcpy` builtin to bar's body.
  void bar(char* data, size_t count) __attribute__((no_builtin("memcpy"))) {
    // The compiler is allowed to convert the loop into
    // `__builtin_memset(data, 0xFE, count);` but cannot generate any
    // `__builtin_memcpy`
    for (size_t i = 0; i < count; ++i)
      data[i] = 0xFE;
  }
  }];
}
+0 −9
Original line number Diff line number Diff line
@@ -3604,15 +3604,6 @@ def err_attribute_overloadable_no_prototype : Error<
def err_attribute_overloadable_multiple_unmarked_overloads : Error<
  "at most one overload for a given name may lack the 'overloadable' "
  "attribute">;
def warn_attribute_no_builtin_invalid_builtin_name : Warning<
  "'%0' is not a valid builtin name for %1">,
  InGroup<DiagGroup<"invalid-no-builtin-names">>;
def err_attribute_no_builtin_wildcard_or_builtin_name : Error<
  "empty %0 cannot be composed with named ones">;
def err_attribute_no_builtin_on_non_definition : Error<
  "%0 attribute is permitted on definitions only">;
def err_attribute_no_builtin_on_defaulted_deleted_function : Error<
  "%0 attribute has no effect on defaulted or deleted functions">;
def warn_ns_attribute_wrong_return_type : Warning<
  "%0 attribute only applies to %select{functions|methods|properties}1 that "
  "return %select{an Objective-C object|a pointer|a non-retainable pointer}2">,
+4 −20
Original line number Diff line number Diff line
@@ -1853,27 +1853,11 @@ void CodeGenModule::ConstructAttributeList(
    if (const FunctionDecl *Fn = dyn_cast<FunctionDecl>(TargetDecl)) {
      AddAttributesFromFunctionProtoType(
          getContext(), FuncAttrs, Fn->getType()->getAs<FunctionProtoType>());
      // Don't use [[noreturn]] or _Noreturn for a call to a virtual function.
      // These attributes are not inherited by overloads.
      const CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(Fn);
      const bool IsVirtualCall = MD && MD->isVirtual();
      // Don't use [[noreturn]], _Noreturn or [[no_builtin]] for a call to a
      // virtual function. These attributes are not inherited by overloads.
      if (!(AttrOnCallSite && IsVirtualCall)) {
        if (Fn->isNoReturn())
      if (Fn->isNoReturn() && !(AttrOnCallSite && MD && MD->isVirtual()))
        FuncAttrs.addAttribute(llvm::Attribute::NoReturn);

        if (const auto *NBA = TargetDecl->getAttr<NoBuiltinAttr>()) {
          bool HasWildcard = llvm::is_contained(NBA->builtinNames(), "*");
          if (HasWildcard)
            FuncAttrs.addAttribute("no-builtins");
          else
            for (StringRef BuiltinName : NBA->builtinNames()) {
              SmallString<32> AttributeName;
              AttributeName += "no-builtin-";
              AttributeName += BuiltinName;
              FuncAttrs.addAttribute(AttributeName);
            }
        }
      }
    }

    // 'const', 'pure' and 'noalias' attributed functions are also nounwind.
Loading