[llvm-bugs] [Bug 36344] New: Bad code gen => uninitialized value

via llvm-bugs llvm-bugs at lists.llvm.org
Sun Feb 11 18:06:41 PST 2018


https://bugs.llvm.org/show_bug.cgi?id=36344

            Bug ID: 36344
           Summary: Bad code gen => uninitialized value
           Product: clang
           Version: 5.0
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: -New Bugs
          Assignee: unassignedclangbugs at nondot.org
          Reporter: tydeman at tybor.com
                CC: llvm-bugs at lists.llvm.org

/*
 * Invalid runtime error: MemorySanitizer: use-of-uninitialized-value
 * Due to bad code generation ????
 * Using clang 5.0.1-1 on 64-bit Fedora Linux 27 on Intel core i5

# flags common to both compiler and linker
export CLFLAGS="-fsanitize=memory -fsanitize=undefined
-fno-sanitize=float-cast-overflow -fno-sanitize=float-divide-by-zero"

# flags for compiler
export CFLAGS="-std=c1x -m64 -mfpmath=sse -msse2 -O0 -fno-fast-math -pedantic
-fmath-errno"

 */

static void test_4(void){
  si = func_si( 30*4+14, ((struct bit2){1u,1,1,BOOL_CAST(1)}.pibf), ((struct
bit2){1u,1,1,BOOL_CAST(1)}.pibf), ((struct bit2){1u,1,1,BOOL_CAST(1)}.pibf) );
  ck(si);
  si = func_si( 30*4+14, bits.pibf, bits.pibf, bits.pibf );
  ck(si);

  si = func_si( 30*4+15, ((struct bit2){1u,1,1,BOOL_CAST(1)}.bobf), ((struct
bit2){1u,1,1,BOOL_CAST(1)}.bobf), ((struct bit2){1u,1,1,BOOL_CAST(1)}.bobf) );
  ck(si);
  si = func_si( 30*4+15, bits.bobf, bits.bobf, bits.bobf );
  ck(si);
}

#include <stdio.h>
#include <stdarg.h>
#include <stdbool.h>

#define BOOL_CAST(x) ((bool)(x))

#define ck(a)   \
 if(a){         \
   NumPass++;\
   ckFailed = 0;\
 }else{\
   NumFail++;\
   ckFailed = 1;\
   Line = __LINE__;\
   (void)printf("\nError in line %d in %s\n", Line, __FILE__ );\
   (void)puts( #a );\
 }

static unsigned long int NumFail = 0uL;
static unsigned long int NumPass = 0uL;
static int ckFailed = 0;
static int Line = 0;

#define LDBL long double
static LDBL ld;
static signed int si;
struct bit2 {
  unsigned int uibf : 7;
    signed int sibf : 7;
 /*plain*/ int pibf : 7;
          bool bobf : 1;
  unsigned char after[16];
} bits
 = {1u,1,1,BOOL_CAST(1),{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}} ;

static   signed int func_si( const int i, ... ){
  va_list ap;
    signed int x1, x2, x3;
  va_start(ap,i);
  x1 = (  signed int)va_arg(ap,   signed int );
  x2 = (  signed int)va_arg(ap,   signed int );
  x3 = (  signed int)va_arg(ap,   signed int );
  ck( x1 == x2 );
  ck( x2 == x3 );
  va_end(ap);
  return x3;
}

static LDBL func_ld( const int i, ... ){
  va_list ap;
  LDBL x1, x2, x3;
  va_start(ap,i);
  x1 = (LDBL)va_arg(ap, LDBL );
  x2 = (LDBL)va_arg(ap, LDBL );
  x3 = (LDBL)va_arg(ap, LDBL );
#if 0                   /* change to #if 1 showw that vars have values */
  (void)printf(" i=%i\n", i);
  (void)printf("x1=%Lg\n", x1);
  (void)printf("x2=%Lg\n", x2);
  (void)printf("x3=%Lg\n", x3);
  exit(0);
#endif
  ck( x1 == x2 );       /* invalid error happens here */
  ck( x2 == x3 );
  va_end(ap);
  return x3;
}

static void test_4(void){
#if 1
  si = func_si( 30*4+14, ((struct bit2){1u,1,1,BOOL_CAST(1)}.pibf), ((struct
bit2){1u,1,1,BOOL_CAST(1)}.pibf), ((struct bit2){1u,1,1,BOOL_CAST(1)}.pibf) );
  ck(si);
  si = func_si( 30*4+14, bits.pibf, bits.pibf, bits.pibf );
  ck(si);
#endif

#if 1
  si = func_si( 30*4+15, ((struct bit2){1u,1,1,BOOL_CAST(1)}.bobf), ((struct
bit2){1u,1,1,BOOL_CAST(1)}.bobf), ((struct bit2){1u,1,1,BOOL_CAST(1)}.bobf) );
  ck(si);
  si = func_si( 30*4+15, bits.bobf, bits.bobf, bits.bobf );
  ck(si);
#endif
}

static void test_20(void){
  ld = func_ld( 30*20+20, 1.5L, 1.5L, 1.5L );
  ck(ld);
  ld = func_ld( 30*20+20, ld, ld, ld );
  ck(ld);
}

int main(void){
#if 1           /* change to #if 0 to make "error" go away */
  test_4();
#endif
  test_20();
  (void)printf("No error happened.\n");
  return 0;
}

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20180212/4e3a8c2b/attachment.html>


More information about the llvm-bugs mailing list