-1

I have a bunch of random csmith-generated code I'm trying to compile with clang, but csmith does not cast types explicitly, and it's confusing clang.

Example error:

C:\Users\Steve\Documents\A\a\Csmith\main.cpp:52:568: error: cannot
  initialize an array element of type 'int32_t **volatile'
  (aka 'int **volatile') with an rvalue of type 'void *'
  ...&g_50, &g_50, &g_50, &g_50, &g_50, (void*)0}, {(void*)0, &g_50, &g_50, &...

gcc will just cast it implicitly, and I can't find a way to do this with clang

Help would be much appreciated

M.M
  • 138,810
  • 21
  • 208
  • 365
Steve Dell
  • 575
  • 1
  • 7
  • 23
  • Run `creduce` and post the minimal code snippet that gives you this error. When you get a compiler error that you think is incorrect, also provide the version. – Ben Voigt Jul 28 '14 at 22:33
  • 2
    The problem isn't what you think it is. [Csmith](http://embed.cs.utah.edu/csmith/) claims to output valid C code. Valid C code cannot contain an implicit conversion from `long` to `int **`. Therefore, either clang is misinterpreting the code, or csmith is generating buggy code. Either way, the solution isn't to make clang accept implicit conversions between integers and pointers. Do you have a concrete example program that you think is valid, but clang doesn't? –  Jul 28 '14 at 22:34
  • The file extension doesn't look appropriate for C code, either. – Ben Voigt Jul 28 '14 at 22:35
  • A question would be much appreciated – Lightness Races in Orbit Jul 28 '14 at 22:35
  • It doesn't look like you followed [the directions](http://embed.cs.utah.edu/csmith/using.html) – Ben Voigt Jul 28 '14 at 22:37
  • Very sorry. What I attached is not actually what Csmith generated; I modified it to try and solve the problem. I updated the main post with the true Csmith-generated code. Here's the pastebin of the Csmith code. There's many lines of that code that will reproduce the clang error. Also I'm using clang++, not clang to compile, Ben, which I assumed is for C++ code (yes I know this is C code, but I have C++ wrapping around it in my application) – Steve Dell Jul 28 '14 at 22:50
  • @SteveDell: And now you have [a construct that IS valid in C, and not in C++](http://stackoverflow.com/questions/7016861/why-are-null-pointers-defined-differently-in-c-and-c). Run your compiler in C99 mode (renaming the file so it doesn't end in `.cpp` may help). – Ben Voigt Jul 28 '14 at 22:50
  • Unfortunately, no luck with renaming the file. Is there a switch on clang to force it to treat it as C? `C:\Users\Steve\Documents\A\a\Csmith\main.c:52:568: error: cannot initialize an array element of type 'int32_t **volatile' (aka 'int **volatile') with an rvalue of type 'void *' ...&g_50, &g_50, &g_50, &g_50, &g_50, (void*)0}, {(void*)0, &g_50, &g_50, &...` – Steve Dell Jul 28 '14 at 22:55
  • @SteveDell: Your previous comment suggests that you know how (use `clang`), and that you were using `clang++` for other reasons. Well, figure out some way to separate the C code from the C++ code, as `csmith` doesn't produce valid C++. Or find a `csmith` option that uses `(0)` as the null pointer, instead of `(void*)0`. – Ben Voigt Jul 28 '14 at 22:59
  • You were a tremendous help, Ben! Now it's compiling fine, but as it's my first time using clang, I'm having linking issues (clang is having trouble launching the linker). I'm going to create a separate question for that. – Steve Dell Jul 28 '14 at 23:25
  • I wish I could +rep you but if I'm able to, stackoverflow does a really fine job hiding it. – Steve Dell Jul 28 '14 at 23:26

1 Answers1

1

Are you compiling in C++ mode?

See this link on how to change it to C99 mode.

Another issue you may have is that even though you are compiling in C99, clang tends to be more picky about what it will compile. This is taken straight from the Clang compatibility pages:

However, Clang is more strict than other popular compilers, and may reject incorrect code that other compilers allow. This page documents common compatibility and portability issues with Clang to help you understand and fix the problem in your code when Clang emits an error message.

Additionally you might have a problem with l-value casts, which are a documented issue between clang and GCC. You can find that information here.

If you supply the exact source code that causes the compile error, it will be easier to help.

Community
  • 1
  • 1
havocheavy
  • 120
  • 5
  • Hi havocheavy - Thanks to Ben above, I'm able to get the file to compile now. Although I'm having linking errors which are really frustrating. I'm going to make a new question soon regarding the linking errors – Steve Dell Jul 28 '14 at 23:46