2024-05-31 05:22 AEST

View Issue Details Jump to Notes ]
IDProjectCategoryView StatusLast Update
0000250mercuryBugpublic2012-05-10 10:12
Assigned Towangp 
Product Version 
Target VersionFixed in Version 
Summary0000250: GCC warnings: used but never defined
DescriptionIn Mercury 11.07 (grade: asm_fast.gc), all non-trivial Mercury programs are causing GCC 4.6 to spit out lots and lots of "used but never defined" warnings. These seem to be caused whenever a function or predicate is curried. The simplest complete example I can think of is this:

:- module gcc_warn.
:- interface.
:- import_module io.
:- pred main(io::di, io::uo) is det.

:- implementation.
:- import_module int.

:- pred add(int::in, int::in, int::out) is det.
add(X, Y, Z) :-
    Z = X + Y.

:- func add_wrap(int, int) = int.
add_wrap(X, Y) = Z :-
    add(X)(Y, Z).

main(!IO) :-
    io.write(add_wrap(1, 2), !IO),


$ mmc gcc_warn.m

causes GCC to give the warning:

gcc_warn.c:80:1: warning: ‘mercury__gcc_warn__add_3_0’ used but never defined [enabled by default]

The warning is generated due to add_wrap, which curries the add predicate. It also happens if add is a function.
Additional Information$ gcc --version
gcc (Ubuntu/Linaro 4.6.1-9ubuntu3) 4.6.1

Using Mercury 11.07 beta 2011-11-16 / grade asm_fast.gc. This started happening when I upgraded to Mercury 11.07, but I also upgraded to Ubuntu 11.10 at the same time, so I don't know whether Mercury or GCC regressed.

The specific GCC command that caused this warning was:
gcc -I/usr/local/mercury-11.07-beta-2011-11-16/lib/mercury/lib/asm_fast.gc/inc -I/usr/local/mercury-11.07-beta-2011-11-16/lib/mercury/conf -I/usr/local/mercury-11.07-beta-2011-11-16/lib/mercury/inc -O2 -fomit-frame-pointer -fno-strict-aliasing -DMR_USE_GCC_GLOBAL_REGISTERS -DMR_USE_GCC_NONLOCAL_GOTOS -DMR_USE_ASM_LABELS -fno-builtin -fno-omit-frame-pointer -fno-defer-pop -fno-function-cse -fno-gcse -fno-move-loop-invariants -DMR_CONSERVATIVE_GC -DMR_BOEHM_GC -DMR_TAGBITS=2 -ansi -Wall -Wwrite-strings -Wshadow -Wmissing-prototypes -Wno-unused -Wno-uninitialized -Wstrict-prototypes -c gcc_warn.c -o gcc_warn.o

The line of C code in question is:
TagsNo tags attached.
Attached Files




wangp (developer)

Is there any gcc option to suppress the warning now? Otherwise it's just a simple change to util/mfiltercc.c


mgiuca (reporter)

If it was "defined but not used" then suppression would be fine. But I'm a bit nervous about suppressing "used but not defined" errors -- it implies that something could possibly go horribly wrong. (I'm not sure if this is the same thing as when you call a function in C that hasn't been declared, and the types might not convert properly.) Since I don't know exactly what all those Mercury macros do, I'll let you decide, but I'd say it's best if Mercury does whatever GCC is asking it to do rather than suppressing the warning.


juliensf (administrator)

Suppressing this warning is fine. The problem here is that the definition is given is assembly language
and the compiler can't see that it exists. Note that the function that causes the trouble,

static void mercury__gcc_warn__add_3_0(void) __asm__("_entry_" "mercury__gcc_warn__add_3_0");

is also mapped to the same name in assembler.

The problems here are:
(1) the warning has changed in gcc 4.6 so mfiltercc isn't filtering it properly
(2) there's no way to disable the warning AFAIK.

The problem has existed since about gcc 4.3, i.e. it's not specific to 4.6.


wangp (developer)

Fix committed today.

-Issue History
Date Modified Username Field Change
2012-01-12 14:34 mgiuca New Issue
2012-01-12 14:34 mgiuca File Added: gcc_warn.m
2012-01-12 17:36 wangp Note Added: 0000444
2012-01-12 18:01 mgiuca Note Added: 0000445
2012-01-12 18:38 juliensf Note Added: 0000446
2012-05-10 10:12 wangp Note Added: 0000454
2012-05-10 10:12 wangp Status new => resolved
2012-05-10 10:12 wangp Resolution open => fixed
2012-05-10 10:12 wangp Assigned To => wangp
+Issue History