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

msan: incorrect function/location/name for stack variables

Open KernelAddress opened this issue 8 years ago • 4 comments

Bugzilla Link 37208
Version unspecified
OS Linux
CC @dwblaikie,@eugenis,@ramosian-glider,@kcc,@vitalybuka

Extended Description

#include <stdio.h>

int foo() { volatile int x; return x; }

int bar() { return foo(); }

int main() { printf("start\n"); int x = bar(); if (x) printf("here\n"); return 0; }

$ clang -v clang version 7.0.0 (trunk 326052) $ clang test.c -fsanitize=memory -fsanitize-memory-track-origins -g -O2 $ ./a.out

==261759==WARNING: MemorySanitizer: use-of-uninitialized-value #​0 0x499cda in main test.c:18:6

Uninitialized value was created by an allocation of 'x.i.i' in the stack frame of function 'main' #​0 0x499c20 in main test.c:15

SUMMARY: MemorySanitizer: use-of-uninitialized-value test.c:18:6 in main

The variable is called 'x', not 'x.i.i'. The variable is allocated in function 'foo', not 'main'. The variable is allocated at line 5, not 15. 15 does not even hint at the inlined function that allocated the variable.

KernelAddress avatar Apr 23 '18 07:04 KernelAddress

For builds with full debug info, this should be reasonably easy to fix.

eugenis avatar Jun 12 '18 18:06 eugenis

-gmlt is not a problem in my case (kernel).

FWIW gmlt produces debug info with inlining, is it some internal llvm metadata problem only?

KernelAddress avatar Jun 12 '18 18:06 KernelAddress

This description is generated in the MSan instrumentation pass. We could try decoding debug metadata to improve it. The problem is, there is no debug metadata in -gmlt builds (or it does not describe inlining, in any case). Maybe we could emit it in gmlt+msan but drop after MSan pass.

eugenis avatar Jun 12 '18 18:06 eugenis

Eugeni, any idea how hard to fix this?

vitalybuka avatar Jun 12 '18 00:06 vitalybuka