llvm-project icon indicating copy to clipboard operation
llvm-project copied to clipboard

kmsan: false negative on bitfields

Open KernelAddress opened this issue 7 years ago • 1 comments

Bugzilla Link 40510
Version unspecified
OS Linux
CC @ramosian-glider

Extended Description

clang version 8.0.0 (trunk 350842)

struct A { int a:1; int b:1; int c:1; int d:1; int e:1; };

A* newA() { A* a = new A; a->c = 0; a->d = 1; return a; }

#include <stdio.h>

int main() { volatile A* volatile a = newA(); if (a->b) printf("1\n"); return 0; }

clang++ /tmp/init.cc -O2 -fsanitize=memory -g && ./a.out

Does not report the use of uninit. Generated code initializes whole shadow to 0:

0000000000000000 <_Z4newAv>: 0: 53 push %rbx 1: 48 8b 05 00 00 00 00 mov 0x0(%rip),%rax # 8 <_Z4newAv+0x8> 8: 64 48 c7 00 00 00 00 movq $0x0,%fs:(%rax) f: 00 10: 48 8b 1d 00 00 00 00 mov 0x0(%rip),%rbx # 17 <_Z4newAv+0x17> 17: 64 48 c7 03 00 00 00 movq $0x0,%fs:(%rbx) 1e: 00 1f: bf 04 00 00 00 mov $0x4,%edi 24: e8 00 00 00 00 callq 29 <_Z4newAv+0x29> 29: 48 b9 00 00 00 00 00 movabs $0x500000000000,%rcx 30: 50 00 00 33: 48 31 c1 xor %rax,%rcx 36: c6 01 00 movb $0x0,(%rcx) 39: c6 00 08 movb $0x8,(%rax) 3c: 64 48 c7 03 00 00 00 movq $0x0,%fs:(%rbx) 43: 00 44: 5b pop %rbx 45: c3 retq

KernelAddress avatar Jan 29 '19 09:01 KernelAddress

assigned to @eugenis

KernelAddress avatar Jan 29 '19 09:01 KernelAddress