https://gcc.gnu.org/bugzilla/show_bug.cgi?id=119192
Bug ID: 119192 Summary: ICE if TBITSIZE is used in an expression Product: gcc Version: 15.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: modula2 Assignee: gaius at gcc dot gnu.org Reporter: gaius at gcc dot gnu.org Target Milestone: --- Using TBITSIZE in an expression causes an ICE in cc1gm2. Consider: $ cat simplepacked.mod MODULE simplepacked ; FROM libc IMPORT printf, exit ; FROM SYSTEM IMPORT TBITSIZE, ROTATE ; TYPE settype = SET OF [0..8] ; psettype = PACKEDSET OF [0..8] ; PROCEDURE assert (cond: BOOLEAN; line: CARDINAL; message: ARRAY OF CHAR) ; BEGIN IF NOT cond THEN printf ("assert failed %s at line %d\n", message, line) ; exit (1) END END assert ; PROCEDURE testset ; VAR a, b: settype ; BEGIN a := settype {1} ; b := a ; (* Assumes that the bitset will be contained in <= 64 bits, most likely 32. But probably safe to assume <= 64 bits for some time. *) printf ("TBITSIZE (a) = %d\n", TBITSIZE (a)); (* assert (TBITSIZE (a) <= 32, __LINE__, "TBITSIZE <= 32") ; *) assert (a = b, __LINE__, "comparision between variable sets") ; assert (a = settype {1}, __LINE__, "comparision between variable and constant sets") ; assert (b = settype {1}, __LINE__, "comparision between variable and constant sets") ; assert (settype {1} = settype {1}, __LINE__, "comparision between constant sets") ; assert (settype {1} # settype {2}, __LINE__, "comparision between constant sets") ; assert (ROTATE (settype {1}, 1) = ROTATE (settype {1}, 1), __LINE__, "comparision between constant rotated sets") ; assert (ROTATE (settype {1}, 1) # ROTATE (settype {2}, 1), __LINE__, "comparision between constant rotated sets") ; assert (ROTATE (a, 1) = settype {2}, __LINE__, "comparision between rotated variable and constant sets") ; assert (ROTATE (a, -1) = settype {0}, __LINE__, "comparision between rotated variable and constant sets") ; END testset ; PROCEDURE testpset ; VAR a, b: psettype ; BEGIN a := psettype {1} ; b := a ; (* Packed set should be stored in a BYTE. *) printf ("TBITSIZE (a) = %d\n", TBITSIZE (a)); assert (TBITSIZE (a) <= 32, __LINE__, "TBITSIZE <= 32 ( packed set") ; assert (a = b, __LINE__, "comparision between variable packed sets") ; assert (a = psettype {1}, __LINE__, "comparision between variable and constant packed sets") ; assert (b = psettype {1}, __LINE__, "comparision between variable and constant packed sets") ; assert (psettype {1} = psettype {1}, __LINE__, "comparision between constant packed sets") ; assert (psettype {1} # psettype {2}, __LINE__, "comparision between constant packed sets") ; assert (ROTATE (psettype {1}, 1) = ROTATE (psettype {1}, 1), __LINE__, "comparision between constant rotated packed sets") ; assert (ROTATE (psettype {1}, 1) # ROTATE (psettype {2}, 1), __LINE__, "comparision between constant rotated packed sets") ; assert (ROTATE (a, 1) = psettype {2}, __LINE__, "comparision between rotated variable and constant packed sets") ; assert (ROTATE (a, -1) = settype {0}, __LINE__, "comparision between rotated variable and constant packed sets") ; END testpset ; BEGIN testset ; testpset END simplepacked. $ gm2 -g -fiso simplepacked.mod In function ‘testset’: cc1gm2: internal compiler error: TBITSIZE function should already have been folded 0x2eed73b internal_error(char const*, ...) ../../gcc/diagnostic-global-context.cc:517 0x433930 m2linemap_internal_error ../../gcc/m2/gm2-gcc/m2linemap.cc:254 0x5b1a32 M2Emit_InternalError ../../gcc/m2/gm2-compiler/M2Emit.mod:56 0x4832a9 M2Error_InternalError ../../gcc/m2/gm2-compiler/M2Error.mod:168 0x4a9074 CodeStandardFunction ../../gcc/m2/gm2-compiler/M2GenGCC.mod:5030 0x49f633 CodeStatement ../../gcc/m2/gm2-compiler/M2GenGCC.mod:698 0x49d427 M2GenGCC_ConvertQuadsToTree ../../gcc/m2/gm2-compiler/M2GenGCC.mod:443 0x5069da M2Scope_ForeachScopeBlockDo2 ../../gcc/m2/gm2-compiler/M2Scope.mod:432 0x47cdff M2Code_CodeBlock ../../gcc/m2/gm2-compiler/M2Code.mod:466 0x4565b9 Lists_ForeachItemInListDo ../../gcc/m2/gm2-compiler/Lists.mod:315 0x53a303 SymbolTable_ForeachProcedureDo ../../gcc/m2/gm2-compiler/SymbolTable.mod:14249 0x47ce70 M2Code_CodeBlock ../../gcc/m2/gm2-compiler/M2Code.mod:491 0x47d790 DoCodeBlock ../../gcc/m2/gm2-compiler/M2Code.mod:227 0x47cd3a M2Code_Code ../../gcc/m2/gm2-compiler/M2Code.mod:288 0x47e90f Compile ../../gcc/m2/gm2-compiler/M2Comp.mod:272 0x47e2ed M2Comp_compile ../../gcc/m2/gm2-compiler/M2Comp.mod:287 0x440ef0 init_PerCompilationInit(char const*) ../../gcc/m2/gm2-gcc/init.cc:207 0x407ab0 gm2_parse_input_files ../../gcc/m2/gm2-lang.cc:836 0x407ae1 gm2_langhook_parse_file ../../gcc/m2/gm2-lang.cc:843