public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/111769] New: Annotate function definitions and calls to facilitate link-time checking
@ 2023-10-11 11:41 david at westcontrol dot com
  2023-10-11 13:21 ` [Bug c/111769] " rguenth at gcc dot gnu.org
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: david at westcontrol dot com @ 2023-10-11 11:41 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111769

            Bug ID: 111769
           Summary: Annotate function definitions and calls to facilitate
                    link-time checking
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: david at westcontrol dot com
  Target Milestone: ---

This is an enhancement idea, rather than a bug, and would require linker
support as well as compiler support.

In C, it is possible to define a function with one set of parameters (number
and type) in one translation unit, and declare and use it with a different set
in a different translation unit.  This is undefined behaviour, and generally a
really bad idea, but it can't be spotted by the toolchain unless you use LTO.

In C++, you don't see the same effect as different name mangling would result
in linker failures.

Would it be possible for the C compiler, when emitting an external linkage
function definition and the use (or possibly declaration) of a function (for
calling or taking its address), to add a directive or debug info section entry
giving the function type in active use?  These could then be checked at link
time, even without LTO, to catch mismatches.

My suggestion would be to use the existing C++ name-mangling scheme to encode
the function types.  Thus the declaration and definition of "int square(int
num)" would be annotated with a note that the function "square" has signature
"_Z6squarei".

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2023-10-12  7:29 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-10-11 11:41 [Bug c/111769] New: Annotate function definitions and calls to facilitate link-time checking david at westcontrol dot com
2023-10-11 13:21 ` [Bug c/111769] " rguenth at gcc dot gnu.org
2023-10-11 16:53 ` pinskia at gcc dot gnu.org
2023-10-12  7:18 ` david at westcontrol dot com
2023-10-12  7:29 ` david at westcontrol dot com

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).