clang bug with constant folding alignment?
clang bug with constant folding alignment?
- Subject: clang bug with constant folding alignment?
- From: Daniel Vollmer <email@hidden>
- Date: Thu, 03 Nov 2011 13:37:55 +0100
Hello all,
Normally, I'd just write a bug-report, but as I cannot log into Apple's bug-reporter at the moment ("An error has occurred. Please report the error to Apple Inc. by emailing the error detail to email@hidden."), I thought I'd try here.
Since upgrading from Xcode 4.1 to 4.2, I cannot use clang anymore to compile our CFD code. It seems to me, that the bug the same as http://llvm.org/bugs/show_bug.cgi?id=10514 but as I'm not sure how the fix relates to the clang version / release used in Xcode, I thought I'd make sure.
Apple clang version 3.0 (tags/Apple/clang-211.10.1) (based on LLVM 3.0svn)
Target: x86_64-apple-darwin11.2.0
The following reduced test-case crashes on the initialization of the char-array on the stack with "Interpolation smoother" in the function smooth_fmg_interpolations_pntmem_req() when optimization is >= -O2.
-------
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
typedef struct
{
char *name; /* name refered to in parameter file */
int id; /* smoother identification */
void *smoother; /* the smoother function */
void *pntmem_req; /* the smoother pntmem_req */
double epsilon; /* relaxation parameter (epsilon) */
int steps; /* number of relaxation iterations */
} Smoother;
static Smoother sm_interpolation =
{
"Interpolation smoother", // CLANG: this constant is probably folded with the other instance
1,
NULL,
NULL,
0.2,
2
};
typedef struct
{
int max_variables;
char *max_comment;
int min_variables;
char *min_comment;
} PntMemInfo;
PntMemInfo set_default_pntmem_info(void)
{
PntMemInfo info;
info.max_variables = 0;
info.min_variables = 0;
info.max_comment = (char *)malloc(sizeof (char));
info.min_comment = (char *)malloc(sizeof (char));
strcpy(info.max_comment, "");
strcpy(info.min_comment, "");
return info;
} /* set_default_pntmem_info() */
PntMemInfo update_pntmem_info(PntMemInfo info, char *local_comment)
{
PntMemInfo new_info;
int len = strlen(local_comment),
len1 = 0;
new_info.max_variables = info.max_variables;
len1 = len + strlen(info.max_comment) + 10;
new_info.max_comment = (char *)malloc(len1 * sizeof(char));
sprintf(new_info.max_comment, "%s %i\n %s", local_comment,
info.max_variables,
info.max_comment);
new_info.min_variables = info.min_variables;
len1 = len + strlen(info.min_comment) + 10;
new_info.min_comment = (char *)malloc(len1 * sizeof(char));
sprintf(new_info.min_comment, "%s %i\n %s", local_comment,
info.min_variables,
info.min_comment);
free(info.max_comment);
free(info.min_comment);
return new_info;
} /* update_pntmem_info() */
PntMemInfo smooth_fmg_interpolations_pntmem_req(void *grid)
{
char comment[] = "Interpolation smoother"; // CLANG: it seems the stack alignment of the constant is wrong for movaps here
PntMemInfo info = set_default_pntmem_info();
if(sm_interpolation.steps != 0)
{
/* epsilon[] */
info.max_variables = 1;
info.min_variables = 1;
// info = add_pntmem_info(info, sm_interpolation.pntmem_req(grid));
}
return update_pntmem_info(info, comment);
} /* smooth_fmg_interpolations_pntmem_req() */
// CLANG: might be the same as http://llvm.org/bugs/show_bug.cgi?id=10514
// > clang -O2 -g clang_bug.c
// > ./a.out
// Interpolation smoother
// Segmentation fault: 11
// gdb
// Program received signal EXC_BAD_ACCESS, Could not access memory.
// Reason: 13 at address: 0x0000000000000000
// main (argc=<value temporarily unavailable, due to optimizations>, argv=<value temporarily unavailable, due to optimizations>) at clang_bug.c:104
// 104 PntMemInfo info = smooth_fmg_interpolations_pntmem_req(NULL);
// (gdb) x/i $pc
// 0x100000d98 <smooth_fmg_interpolations_pntmem_req>: movaps 0x123(%rip),%xmm0 # 0x100000ec2
// 0x100000ec2 & 15 = 2 (i.e. not 16-byte aligned)
int main (int argc, char const *argv[])
{
printf("%s\n", sm_interpolation.name);
PntMemInfo info = smooth_fmg_interpolations_pntmem_req(NULL);
return 0;
}
-------
Does anyone know how the Xcode clang relates to official clang revision numbers, or whether this is a different bug?
Thanks,
Daniel. _______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden