https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109426
Bug ID: 109426 Summary: Gcc runs into Infinite loop, when resolving templates Product: gcc Version: 12.2.1 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: zhonghao at pku dot org.cn Target Milestone: --- The code is as follows: typedef struct astruct_d { void *data; } astruct; /* Generate a whole bunch of unique fake mallocs, this keeps the vartrack dump simpler to understand (all the "size" arguments have a unique name). */ #define DE0(X) \ void *malloc##X (unsigned long size##X); #define DE1(X) \ DE0(X##0) DE0(X##1) DE0(X##2) DE0(X##3) DE0(X##4) \ DE0(X##5) DE0(X##6) DE0(X##7) DE0(X##8) DE0(X##9) #define DE2(X) \ DE1(X##0) DE1(X##1) DE1(X##2) DE1(X##3) DE1(X##4) \ DE1(X##5) DE1(X##6) DE1(X##7) DE1(X##8) DE1(X##9) #define DE3(X) \ DE2(X##0) DE2(X##1) DE2(X##2) DE2(X##3) DE2(X##4) \ DE2(X##5) DE2(X##6) DE2(X##7) DE2(X##8) DE2(X##9) #define DE4(X) \ DE3(X##0) DE3(X##1) DE3(X##2) DE3(X##3) DE3(X##4) \ DE3(X##5) DE3(X##6) DE3(X##7) DE3(X##8) DE3(X##9) DE4(0) #undef DE0 #undef DE1 #undef DE2 #undef DE3 #undef DE4 void foo (void) { /* Now call all those mallocs and generate a series of variables while at it. */ #define DE0(X) \ astruct *A##X = (astruct *) malloc##X(sizeof (astruct)); #define DE1(X) \ DE0(X##0) DE0(X##1) DE0(X##2) DE0(X##3) DE0(X##4) \ DE0(X##5) DE0(X##6) DE0(X##7) DE0(X##8) DE0(X##9) #define DE2(X) \ DE1(X##0) DE1(X##1) DE1(X##2) DE1(X##3) DE1(X##4) \ DE1(X##5) DE1(X##6) DE1(X##7) DE1(X##8) DE1(X##9) #define DE3(X) \ DE2(X##0) DE2(X##1) DE2(X##2) DE2(X##3) DE2(X##4) \ DE2(X##5) DE2(X##6) DE2(X##7) DE2(X##8) DE2(X##9) #define DE4(X) \ DE3(X##0) DE3(X##1) DE3(X##2) DE3(X##3) DE3(X##4) \ DE3(X##5) DE3(X##6) DE3(X##7) DE3(X##8) DE3(X##9) DE4(0) DE4(1) } GCC runs into an infinite loop: code0.c:35:18: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast] 35 | astruct *A##X = (astruct *) malloc##X(sizeof (astruct)); | ^ code0.c:37:32: note: in expansion of macro ‘DE0’ 37 | DE0(X##0) DE0(X##1) DE0(X##2) DE0(X##3) DE0(X##4) \ | ^~~ code0.c:41:42: note: in expansion of macro ‘DE1’ 41 | DE1(X##5) DE1(X##6) DE1(X##7) DE1(X##8) DE1(X##9) | ^~~ code0.c:44:2: note: in expansion of macro ‘DE2’ 44 | DE2(X##5) DE2(X##6) DE2(X##7) DE2(X##8) DE2(X##9) | ^~~ code0.c:46:22: note: in expansion of macro ‘DE3’ 46 | DE3(X##0) DE3(X##1) DE3(X##2) DE3(X##3) DE3(X##4) \ | ^~~ code0.c:49:1: note: in expansion of macro ‘DE4’ 49 | DE4(1) | ^~~