[LLVMbugs] [Bug 14300] New: stack alignment leading to corrupt values of variables

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Fri Nov 9 06:07:49 PST 2012


http://llvm.org/bugs/show_bug.cgi?id=14300

             Bug #: 14300
           Summary: stack alignment leading to corrupt values of variables
           Product: clang
           Version: unspecified
          Platform: PC
        OS/Version: Linux
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: C++
        AssignedTo: unassignedclangbugs at nondot.org
        ReportedBy: rahul.s1 at samsung.com
                CC: dgregor at apple.com, llvmbugs at cs.uiuc.edu
    Classification: Unclassified


For the below Test Case with O1 optimization , the value of m and n has got
corrupted after call to foo() function which is leading to garbage value for LL
variable . 



#include <stddef.h>
#ifdef DEBUG
#include <stdio.h>
#endif

#ifdef  __cplusplus
extern "C" void abort (void);
#else
extern void abort (void);
#endif

int
check_int (int *i, int align)
{
  *i = 20;
  if ((((ptrdiff_t) i) & (align - 1)) != 0)
    {
#ifdef DEBUG
      printf ("\nUnalign address (%d): %p!\n", align, i);
#endif
      abort ();
    }
  return *i;
}

void
check (void *p, int align)
{
  if ((((ptrdiff_t) p) & (align - 1)) != 0)
    {
#ifdef DEBUG
      printf ("\nUnalign address (%d): %p!\n", align, p);
#endif
      abort ();
    }
}

#ifndef ALIGNMENT
#define ALIGNMENT       64
#endif

typedef int t_align __attribute__((aligned(ALIGNMENT)));


int global, global2;
void bar()
{
    volatile t_align a = 1;
        int i,j,k,l,m,n;
        i=j=k=0;
      for (i=0; i < global; i++)
      for (j=0; j < i; j++)
      for (k=0; k < j; k++)
      for (l=0; l < k; l++)
      for (m=0; m < l; m++)
      for (n=0; n < m; n++)
             global2 = k;
    if (check_int ((int *) &a,  __alignof__(a)) != a)
      abort ();
    throw 0;
}

void foo()
{
    bar();
}

int main()
{
    int ll = 1;
        int i = 0,j = 1,k = 2,l = 3,m = 4,n = 5;
    try {
        for (; i < global; i++)
      for (; j < i; j++)
      for (; k < j; k++)
      for (; l < k; l++)
      for (; m < l; m++)
      for (; n < m; n++)
             global2 = k;
      foo();
    }
    catch (...)
    {
    }
    ll = i+j+k+l+m+n;
    if (ll != 15)
    {
#ifdef DEBUG
        printf("FAIL: sum %d != 15\n", ll);
#endif
        abort();
    }
    return 0;
}

-- 
Configure bugmail: http://llvm.org/bugs/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.



More information about the llvm-bugs mailing list