Skip to content

Commit d293417

Browse files
author
serge-sans-paille
committed
Add __warn_memset_zero_len builtin as a workaround for glibc issue
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
1 parent d437fba commit d293417

File tree

3 files changed

+12
-0
lines changed

3 files changed

+12
-0
lines changed

clang/include/clang/Basic/Builtins.def

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -788,6 +788,9 @@ BUILTIN(__builtin_abort, "v", "Fnr")
788788
BUILTIN(__builtin_index, "c*cC*i", "Fn")
789789
BUILTIN(__builtin_rindex, "c*cC*i", "Fn")
790790

791+
// ignored glibc builtin, see https://sourceware.org/bugzilla/show_bug.cgi?id=25399
792+
BUILTIN(__warn_memset_zero_len, "v", "nU")
793+
791794
// Microsoft builtins. These are only active with -fms-extensions.
792795
LANGBUILTIN(_alloca, "v*z", "n", ALL_MS_LANGUAGES)
793796
LANGBUILTIN(__annotation, "wC*.","n", ALL_MS_LANGUAGES)

clang/lib/CodeGen/CGBuiltin.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3222,6 +3222,8 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl GD, unsigned BuiltinID,
32223222
Builder.CreateZExt(EmitSignBit(*this, EmitScalarExpr(E->getArg(0))),
32233223
ConvertType(E->getType())));
32243224
}
3225+
case Builtin::BI__warn_memset_zero_len:
3226+
return RValue::getIgnored();
32253227
case Builtin::BI__annotation: {
32263228
// Re-encode each wide string to UTF8 and make an MDString.
32273229
SmallVector<Metadata *, 1> Strings;

clang/test/CodeGen/builtins.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -453,6 +453,13 @@ void test_builtin_launder(int *p) {
453453
int *d = __builtin_launder(p);
454454
}
455455

456+
// __warn_memset_zero_len should be NOP, see https://sourceware.org/bugzilla/show_bug.cgi?id=25399
457+
// CHECK-LABEL: define void @test___warn_memset_zero_len
458+
void test___warn_memset_zero_len() {
459+
// CHECK-NOT: @__warn_memset_zero_len
460+
__warn_memset_zero_len();
461+
}
462+
456463
// Behavior of __builtin_os_log differs between platforms, so only test on X86
457464
#ifdef __x86_64__
458465

0 commit comments

Comments
 (0)