Skip to content

Commit

Permalink
Add __warn_memset_zero_len builtin as a workaround for glibc issue
Browse files Browse the repository at this point in the history
Glibc issue: https://sourceware.org/bugzilla/show_bug.cgi?id=25399
The fix consist in considering the missing function as a builtin lowered to a nop.

Differential Revision: https://reviews.llvm.org/D72869

(cherry picked from commit d293417)
  • Loading branch information
serge-sans-paille committed Jan 17, 2020
1 parent 2d2d057 commit cd4c65f
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 0 deletions.
3 changes: 3 additions & 0 deletions clang/include/clang/Basic/Builtins.def
Expand Up @@ -788,6 +788,9 @@ BUILTIN(__builtin_abort, "v", "Fnr")
BUILTIN(__builtin_index, "c*cC*i", "Fn")
BUILTIN(__builtin_rindex, "c*cC*i", "Fn")

// ignored glibc builtin, see https://sourceware.org/bugzilla/show_bug.cgi?id=25399
BUILTIN(__warn_memset_zero_len, "v", "nU")

// Microsoft builtins. These are only active with -fms-extensions.
LANGBUILTIN(_alloca, "v*z", "n", ALL_MS_LANGUAGES)
LANGBUILTIN(__annotation, "wC*.","n", ALL_MS_LANGUAGES)
Expand Down
2 changes: 2 additions & 0 deletions clang/lib/CodeGen/CGBuiltin.cpp
Expand Up @@ -3222,6 +3222,8 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl GD, unsigned BuiltinID,
Builder.CreateZExt(EmitSignBit(*this, EmitScalarExpr(E->getArg(0))),
ConvertType(E->getType())));
}
case Builtin::BI__warn_memset_zero_len:
return RValue::getIgnored();
case Builtin::BI__annotation: {
// Re-encode each wide string to UTF8 and make an MDString.
SmallVector<Metadata *, 1> Strings;
Expand Down
7 changes: 7 additions & 0 deletions clang/test/CodeGen/builtins.c
Expand Up @@ -453,6 +453,13 @@ void test_builtin_launder(int *p) {
int *d = __builtin_launder(p);
}

// __warn_memset_zero_len should be NOP, see https://sourceware.org/bugzilla/show_bug.cgi?id=25399
// CHECK-LABEL: define void @test___warn_memset_zero_len
void test___warn_memset_zero_len() {
// CHECK-NOT: @__warn_memset_zero_len
__warn_memset_zero_len();
}

// Behavior of __builtin_os_log differs between platforms, so only test on X86
#ifdef __x86_64__

Expand Down

0 comments on commit cd4c65f

Please sign in to comment.