public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/113378] New: _Static_assert diagnostics lack information when compiling stdin
@ 2024-01-13 16:03 alx at kernel dot org
  2024-01-13 16:07 ` [Bug c/113378] " pinskia at gcc dot gnu.org
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: alx at kernel dot org @ 2024-01-13 16:03 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 113378
           Summary: _Static_assert diagnostics lack information when
                    compiling stdin
           Product: gcc
           Version: 13.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: alx at kernel dot org
  Target Milestone: ---

alx@debian:~/tmp$ cat is/asc.h 
#pragma GCC system_header
#define foo()  _Static_assert(sizeof(int) == sizeof(char))
alx@debian:~/tmp$ cat asc.c 
#include <asc.h>
foo();
alx@debian:~/tmp$ cc -Wall -Wextra -isystem is asc.c
In file included from asc.c:1:
asc.c:2:1: error: static assertion failed
    2 | foo();
      | ^~~
alx@debian:~/tmp$ cc -Wall -Wextra -isystem is -x c - <asc.c
In file included from <stdin>:1:
<stdin>:2:1: error: static assertion failed


I expect the same diagnostic information when compiling stdin.

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

* [Bug c/113378] _Static_assert diagnostics lack information when compiling stdin
  2024-01-13 16:03 [Bug c/113378] New: _Static_assert diagnostics lack information when compiling stdin alx at kernel dot org
@ 2024-01-13 16:07 ` pinskia at gcc dot gnu.org
  2024-01-13 16:16 ` alx at kernel dot org
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: pinskia at gcc dot gnu.org @ 2024-01-13 16:07 UTC (permalink / raw)
  To: gcc-bugs

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

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |diagnostic

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
>I expect the same diagnostic information when compiling stdin.


This part of the diagnostic:
    2 | foo();
      | ^~~

Comes from re-reading in the source file.  Since stdin does not have a source
file backing, there is no output there.

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

* [Bug c/113378] _Static_assert diagnostics lack information when compiling stdin
  2024-01-13 16:03 [Bug c/113378] New: _Static_assert diagnostics lack information when compiling stdin alx at kernel dot org
  2024-01-13 16:07 ` [Bug c/113378] " pinskia at gcc dot gnu.org
@ 2024-01-13 16:16 ` alx at kernel dot org
  2024-01-15  8:35 ` rguenth at gcc dot gnu.org
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: alx at kernel dot org @ 2024-01-13 16:16 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from Alejandro Colomar <alx at kernel dot org> ---
(In reply to Andrew Pinski from comment #1)
> >I expect the same diagnostic information when compiling stdin.
> 
> 
> This part of the diagnostic:
>     2 | foo();
>       | ^~~
> 
> Comes from re-reading in the source file.

Makes sense.

I've tested with other diagnostics, and it's a general thing, not just about
static_assert().  Sorry, for the bogus bug report :)

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

* [Bug c/113378] _Static_assert diagnostics lack information when compiling stdin
  2024-01-13 16:03 [Bug c/113378] New: _Static_assert diagnostics lack information when compiling stdin alx at kernel dot org
  2024-01-13 16:07 ` [Bug c/113378] " pinskia at gcc dot gnu.org
  2024-01-13 16:16 ` alx at kernel dot org
@ 2024-01-15  8:35 ` rguenth at gcc dot gnu.org
  2024-01-15  9:32 ` alx at kernel dot org
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: rguenth at gcc dot gnu.org @ 2024-01-15  8:35 UTC (permalink / raw)
  To: gcc-bugs

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

Richard Biener <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
     Ever confirmed|0                           |1
   Last reconfirmed|                            |2024-01-15

--- Comment #3 from Richard Biener <rguenth at gcc dot gnu.org> ---
We could buffer stdin to a temporary file ... (of course that would defeat it's
purpose somewhat).

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

* [Bug c/113378] _Static_assert diagnostics lack information when compiling stdin
  2024-01-13 16:03 [Bug c/113378] New: _Static_assert diagnostics lack information when compiling stdin alx at kernel dot org
                   ` (2 preceding siblings ...)
  2024-01-15  8:35 ` rguenth at gcc dot gnu.org
@ 2024-01-15  9:32 ` alx at kernel dot org
  2024-01-15  9:38 ` pinskia at gcc dot gnu.org
  2024-01-15 11:18 ` alx at kernel dot org
  5 siblings, 0 replies; 7+ messages in thread
From: alx at kernel dot org @ 2024-01-15  9:32 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #4 from Alejandro Colomar <alx at kernel dot org> ---
On Mon, Jan 15, 2024 at 08:35:53AM +0000, rguenth at gcc dot gnu.org wrote:
> --- Comment #3 from Richard Biener <rguenth at gcc dot gnu.org> ---
> We could buffer stdin to a temporary file ... (of course that would defeat it's
> purpose somewhat).

Not necessarily.  I use stdin for simplicity in small tests.  The
test suite runs some sh(1) scripts, which themselves do more or less:


        #!/usr/bin/bash
        set -Eeuf;
        out="$(mktemp)";
        CFLAGS=...
        LIBS=...

        cc $CFLAGS -o "$out" -x c - $LIBS 2>&1 <<__EOF__ \
        | if ! grep -- '-Werror=pointer-sign' >/dev/null; then \
                >&2 printf '%s\n' "$0:$LINENO: Expected error:
[-Werror=pointer-sign]"; \
                exit 1; \
        else \
                true; \
        fi;
                #include <a2i/str2i.h>

                int
                main(void)
                {
                        unsigned char  n;

                        str2i(signed char, &n, "0");
                }
        __EOF__

And a script can have several of those embedded C programs, without
really having so many .c files.

If the compiler chooses to use a temporary file to improve the
diagnostics, that's not a problem.

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

* [Bug c/113378] _Static_assert diagnostics lack information when compiling stdin
  2024-01-13 16:03 [Bug c/113378] New: _Static_assert diagnostics lack information when compiling stdin alx at kernel dot org
                   ` (3 preceding siblings ...)
  2024-01-15  9:32 ` alx at kernel dot org
@ 2024-01-15  9:38 ` pinskia at gcc dot gnu.org
  2024-01-15 11:18 ` alx at kernel dot org
  5 siblings, 0 replies; 7+ messages in thread
From: pinskia at gcc dot gnu.org @ 2024-01-15  9:38 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #5 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
(In reply to Alejandro Colomar from comment #4)
> 
> Not necessarily.  I use stdin for simplicity in small tests.  The
> test suite

Which testsuite is this?  I should note GCC uses dejagnu (and you can make your
own testsuite using that too for other compilers too) which allows you to do
things like:

```
#include <a2i/str2i.h>

int
main(void)
{
  unsigned char  n;
  str2i(signed char, &n, "0"); /* { dg-error "-Werror=pointer-sign" } */
}
```
Which is easier to maintain than shell scripts like you provided in comment #4.
 Note a simple dejagnu testsuite supports dg-error/dg-warning by default; GCC's
version of dg-error/dg-warning has more features though.

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

* [Bug c/113378] _Static_assert diagnostics lack information when compiling stdin
  2024-01-13 16:03 [Bug c/113378] New: _Static_assert diagnostics lack information when compiling stdin alx at kernel dot org
                   ` (4 preceding siblings ...)
  2024-01-15  9:38 ` pinskia at gcc dot gnu.org
@ 2024-01-15 11:18 ` alx at kernel dot org
  5 siblings, 0 replies; 7+ messages in thread
From: alx at kernel dot org @ 2024-01-15 11:18 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #6 from Alejandro Colomar <alx at kernel dot org> ---
On Mon, Jan 15, 2024 at 09:38:31AM +0000, pinskia at gcc dot gnu.org wrote:
> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113378
> 
> --- Comment #5 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
> (In reply to Alejandro Colomar from comment #4)
> > 
> > Not necessarily.  I use stdin for simplicity in small tests.  The
> > test suite
> 
> Which testsuite is this?

Nothing standard.  Just a hand-written GNUmakefile that runs all scripts
within share/tests/.


        TESTS  := $(shell $(FIND) $(TESTSDIR) -type f | $(GREP) '\.sh$$' |
$(SORT))
        _TESTS := $(patsubst $(srcdir)/share/%,$(builddir)/%.ck.touch,$(TESTS))
        _tests := $(patsubst
$(srcdir)/share/%,$(builddir)/%.ick.touch,$(TESTS))


        _TESTSDIRS := $(patsubst $(srcdir)/share/%,$(builddir)/%/,$(shell
$(FIND) $(TESTSDIR) -type d | $(SORT)))


        $(_TESTSDIRS): | $$(dir $$(@D))
                $(info  MKDIR   $@)
                $(MKDIR) $@


        $(_TESTS): $(builddir)/%.ck.touch: $(srcdir)/share/% $(MK) $(TU_h)
$(_LIB_a) $(_LIB_so_v) | $$(@D)/
                $(info  SH (test)       $@)
                PKG_CONFIG_LIBDIR=$(PCDIR) $<
                touch $@

        $(_tests): $(builddir)/%.ick.touch: $(srcdir)/share/% $(MK) $(_tu_h)
$(_lib_a) $(_lib_so) | $$(@D)/
                $(info  SH (test)       $@)
                $<
                touch $@


        .PHONY: check
        check: $(_TESTS)


        .PHONY: installcheck
        installcheck: $(_tests)


>  I should note GCC uses dejagnu (and you can make your
> own testsuite using that too for other compilers too) which allows you to do
> things like:

I know.  I want to learn to use it if I find some time, and replace my
custom scripts.

> ```
> #include <a2i/str2i.h>
> 
> int
> main(void)
> {
>   unsigned char  n;
>   str2i(signed char, &n, "0"); /* { dg-error "-Werror=pointer-sign" } */
> }
> ```
> Which is easier to maintain than shell scripts like you provided in comment #4.
>  Note a simple dejagnu testsuite supports dg-error/dg-warning by default; GCC's
> version of dg-error/dg-warning has more features though.

Thanks!

Have a lovely day,
Alex

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

end of thread, other threads:[~2024-01-15 11:18 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-01-13 16:03 [Bug c/113378] New: _Static_assert diagnostics lack information when compiling stdin alx at kernel dot org
2024-01-13 16:07 ` [Bug c/113378] " pinskia at gcc dot gnu.org
2024-01-13 16:16 ` alx at kernel dot org
2024-01-15  8:35 ` rguenth at gcc dot gnu.org
2024-01-15  9:32 ` alx at kernel dot org
2024-01-15  9:38 ` pinskia at gcc dot gnu.org
2024-01-15 11:18 ` alx at kernel dot org

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).