This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

C2000-CGT: crash in optimizer when using offsetof to access a different field of a struct

Part Number: C2000-CGT

The attached C file causes cl2000 (v22.6.0.LTS) to crash. The same occurs on any optimization level other than "off", and on all versions I tried, going back to at least v18.12.8.LTS.

$ cl2000 -c container_of_crash.c --opt_level=3

>>>> Optimizer terminated abnormally
>>>> in function _foo()
>>>> in file "container_of_crash.c"
This is caused by a defect in the TI C/C++ Optimizer.
TI Customer Support may be able to suggest a workaround to avoid this.

Upgrading to the newest version of the compiler may fix this problem.

Contact TI in the E2E support forums at http://e2e.ti.com under
"Development Tools", "TI C/C++ Compiler". See the link titled
"Submitting an issue".

We need to see this ENTIRE error message and a complete, reproducible
test case including ALL of the command-line options.
Include the .pp file created by option --preproc_with_comment


>> Compilation failure

container_of_crash.c
Fullscreen
1
2
3
4
5
6
7
8
9
10
11
12
13
14
#define offsetof(type, member) ((unsigned long)&(((type *)0)->member))
#define container_of(ptr, type, member) \
((type *)((unsigned long)(ptr)-offsetof(type, member)))
struct s
{
int a, b, c;
};
int foo(int *pb)
{
return container_of(pb, struct s, b)->c;
}
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX