Skip to content

Instantly share code, notes, and snippets.

@arsenm
Created October 18, 2011 03:01
Show Gist options
  • Save arsenm/1294511 to your computer and use it in GitHub Desktop.
Save arsenm/1294511 to your computer and use it in GitHub Desktop.
Triple AMD compiler bug
/*
3 bugs related to use of an undeclared variable "step"
This does not happen with other names I tried, only step.
Tested: Linux x86_64 (kernel 3.0), Catalyst 11.9, SDK 2.5
Compiling for Cayman
Define BUG to 1, 2, or 3 to experience each bug
*/
#define BUG 3
#if BUG == 1
#warning Bug number 1
/*
Program received signal SIGABRT, Aborted.
0x00007ffff6b8e735 in raise () from /lib/libc.so.6
(gdb) bt
#0 0x00007ffff6b8e735 in raise () from /lib/libc.so.6
#1 0x00007ffff6b8fbab in abort () from /lib/libc.so.6
#2 0x00007ffff5fa401a in ?? () from /opt/amdstream/lib/libamdocl64.so
#3 0x00007ffff5f73950 in ?? () from /opt/amdstream/lib/libamdocl64.so
#4 0x00007ffff5f73a62 in ?? () from /opt/amdstream/lib/libamdocl64.so
#5 0x00007ffff5f73bf9 in ?? () from /opt/amdstream/lib/libamdocl64.so
#6 0x00007ffff5f8b8e9 in ?? () from /opt/amdstream/lib/libamdocl64.so
#7 0x00007ffff53f211b in ?? () from /opt/amdstream/lib/libamdocl64.so
#8 0x00007ffff53d8ea2 in ?? () from /opt/amdstream/lib/libamdocl64.so
#9 0x00007ffff53dc206 in ?? () from /opt/amdstream/lib/libamdocl64.so
#10 0x00007ffff54187b9 in ?? () from /opt/amdstream/lib/libamdocl64.so
#11 0x00007ffff54497f3 in ?? () from /opt/amdstream/lib/libamdocl64.so
#12 0x00007ffff541722e in ?? () from /opt/amdstream/lib/libamdocl64.so
#13 0x00007ffff536f7b4 in ?? () from /opt/amdstream/lib/libamdocl64.so
#14 0x00007ffff53582ca in ?? () from /opt/amdstream/lib/libamdocl64.so
#15 0x00007ffff53aa565 in ?? () from /opt/amdstream/lib/libamdocl64.so
#16 0x00007ffff534e35d in clBuildProgram () from /opt/amdstream/lib/libamdocl64.so
*/
__kernel void breakThings_abort(__global float* restrict a, __global float* restrict b)
{
int i = get_global_id(0);
/* compiler abort()s if you use "step" in a general expression */
i + step;
}
#elif BUG == 2
#warning Bug number 2
/*
Program received signal SIGSEGV, Segmentation fault.
0x00007ffff5960f99 in ?? () from /opt/amdstream/lib/libamdocl64.so
(gdb) bt
#0 0x00007ffff5960f99 in ?? () from /opt/amdstream/lib/libamdocl64.so
#1 0x00007ffff57bcd56 in ?? () from /opt/amdstream/lib/libamdocl64.so
#2 0x00007ffff57d8f43 in ?? () from /opt/amdstream/lib/libamdocl64.so
#3 0x00007ffff59cda76 in ?? () from /opt/amdstream/lib/libamdocl64.so
#4 0x00007ffff59d5f7f in ?? () from /opt/amdstream/lib/libamdocl64.so
#5 0x00007ffff59d646a in ?? () from /opt/amdstream/lib/libamdocl64.so
#6 0x00007ffff598b85d in ?? () from /opt/amdstream/lib/libamdocl64.so
#7 0x00007ffff598cfca in ?? () from /opt/amdstream/lib/libamdocl64.so
#8 0x00007ffff598db1f in ?? () from /opt/amdstream/lib/libamdocl64.so
#9 0x00007ffff598ee03 in ?? () from /opt/amdstream/lib/libamdocl64.so
#10 0x00007ffff5ae1e5f in ?? () from /opt/amdstream/lib/libamdocl64.so
#11 0x00007ffff5f73950 in ?? () from /opt/amdstream/lib/libamdocl64.so
#12 0x00007ffff5f73a62 in ?? () from /opt/amdstream/lib/libamdocl64.so
#13 0x00007ffff5f73bf9 in ?? () from /opt/amdstream/lib/libamdocl64.so
#14 0x00007ffff535156b in ?? () from /opt/amdstream/lib/libamdocl64.so
#15 0x00007ffff5353bc7 in ?? () from /opt/amdstream/lib/libamdocl64.so
#16 0x00007ffff536df18 in ?? () from /opt/amdstream/lib/libamdocl64.so
#17 0x00007ffff538e39f in ?? () from /opt/amdstream/lib/libamdocl64.so
#18 0x00007ffff535825d in ?? () from /opt/amdstream/lib/libamdocl64.so
#19 0x00007ffff53aa565 in ?? () from /opt/amdstream/lib/libamdocl64.so
#20 0x00007ffff534e35d in clBuildProgram () from /opt/amdstream/lib/libamdocl64.so
*/
__kernel void breakThings_sigsegv(__global float* restrict a, __global float* restrict b)
{
int i = get_global_id(0);
/* segfault if you use an undeclared variable "step" in a conditional */
if (step > 0)
{
a[i] = b[i];
}
}
#elif BUG == 3
#warning Bug number 3
/*
/tmp/OCLYJ2VbN.cl(89): warning: #warning directive: Bug number 3
#warning Bug number 3
^
/tmp/OCLYJ2VbN.cl(115): error: expression must be a modifiable lvalue
for (step = 0; step < 5; ++step)
^
/tmp/OCLYJ2VbN.cl(115): warning: operand types are incompatible (
"float (*)(...)" and "int")
for (step = 0; step < 5; ++step)
^
/tmp/OCLYJ2VbN.cl(115): warning: conversion of nonzero integer to pointer
for (step = 0; step < 5; ++step)
^
/tmp/OCLYJ2VbN.cl(115): warning: arithmetic on pointer to void or function type
for (step = 0; step < 5; ++step)
^
/tmp/OCLYJ2VbN.cl(115): error: expression must be a modifiable lvalue
for (step = 0; step < 5; ++step)
^
2 errors detected in the compilation of "/tmp/OCLYJ2VbN.cl".
Internal error: compiler frontend invocation failed. Make sure ATISTREAMSDKROOT is set
clBuildProgram: Build failure (-11): CL_BUILD_PROGRAM_FAILURE
*/
__kernel void breakThings_wtf()
{
for (step = 0; step < 5; ++step)
{
}
}
#else
#error This is no bug
#endif
@arsenm
Copy link
Author

arsenm commented Oct 18, 2011

I think #3 is my favorite

@arsenm
Copy link
Author

arsenm commented Oct 18, 2011

Especially since OpenCL has no function pointers

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment