Skip to content
This repository was archived by the owner on Jun 20, 2019. It is now read-only.

Update to gcc-9-20180729#699

Merged
ibuclaw merged 2 commits intoD-Programming-GDC:masterfrom
belka-ew:gcc-9-20180722
Aug 4, 2018
Merged

Update to gcc-9-20180729#699
ibuclaw merged 2 commits intoD-Programming-GDC:masterfrom
belka-ew:gcc-9-20180722

Conversation

@belka-ew
Copy link
Contributor

The PR adds new - Walloca-larger-than and -Wno-alloca-larger-than command line switches. -Wno-alloca-larger-than is applied when building druntime since the code like following fails otherwise (rt/arrayassign.d):

void* ptmp = (elementSize > buf.sizeof) ? alloca(elementSize) : buf.ptr;

gcc/d/gdc.texi Outdated
where a pragma that is part of the D language, but not implemented by
the compiler, will not get reported.

@item -Walloca-larger-than=@var{n}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should keep it ASCII collated with the other arguments.

gcc/d/lang.opt Outdated
D
; Documented in C

Walloca-larger-than=

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ASCII collation (move it up with the other Wxxx options).

@iain-buclaw-sociomantic

Do you have an example to hand of what's warning? Not just a code example, but the warning message given.

Also, how big is too big for alloca?

@belka-ew
Copy link
Contributor Author

belka-ew commented Jul 23, 2018

../../../../gcc-9-20180722/libphobos/libdruntime/rt/arrayassign.d: In function ‘_d_arrayassign’:
../../../../gcc-9-20180722/libphobos/libdruntime/rt/arrayassign.d:33:18: error: argument to ‘alloca’ may > be too large [-Werror=alloca-larger-than=]
void* ptmp = (elementSize > buf.sizeof) ? alloca(elementSize) : buf.ptr;
^
../../../../gcc-9-20180722/libphobos/libdruntime/rt/arrayassign.d: In function ‘_d_arraysetassign’:
../../../../gcc-9-20180722/libphobos/libdruntime/rt/arrayassign.d:214:9: error: argument to ‘alloca’ may be too large [-Werror=alloca-larger-than=]
tmp = alloca(element_size)[0 .. element_size];

Also, how big is too big for alloca?

No idea. Anyway, as I see it, druntime should be fixed to handle it properly.
Interesting is the manpage for alloca:

If the allocation causes stack overflow, program behavior is undefined.

So it doesn't just return null if it fails but seems to cause undefined behavior.

By the way, I can't reproduce the segfault on slackware; though I haven't tried ubuntu yet.

@ibuclaw
Copy link
Member

ibuclaw commented Jul 26, 2018

What change was made to make the testsuite start passing?

@ibuclaw
Copy link
Member

ibuclaw commented Jul 26, 2018

And secondly, rather than adding a new option, can we just change druntime directly?

assert(elementSize < int.max);
void* ptmp = (elementSize > buf.sizeof) ? alloca(cast(int)elementSize) : buf.ptr;

And raise a PR upstream to address it also.

@belka-ew
Copy link
Contributor Author

belka-ew commented Jul 28, 2018

What change was made to make the testsuite start passing?

Nothing changed; I couldn't reproduce this locally either.

And secondly, rather than adding a new option, can we just change druntime directly?

We can. Why int.max? <= size_t.max would be identical to the current behaviour.

@ibuclaw
Copy link
Member

ibuclaw commented Jul 28, 2018

We can. Why int.max? <= size_t.max would be identical to the current behaviour.

Just an arbitrary restriction really, the important thing to ensure is that can be cast to signed. It looks like the compiler warning default is for any size that may be bigger than half the address space (ptrdiff_t.max would be the real limit).

@belka-ew
Copy link
Contributor Author

assert doesn't work. only if is apparently recognized.

@belka-ew
Copy link
Contributor Author

I reverted the makefiles and adjusted the runtime. But should we keep the option itself? alloca is usable from D, is it a good thing to allow the users to ignore the error?

@belka-ew
Copy link
Contributor Author

I'll raise a PR upstream in the next days.

@ibuclaw
Copy link
Member

ibuclaw commented Jul 28, 2018

assert doesn't work. only if is apparently recognized.

The assert is just for the unittest runner. It would be ignored in release build.

Just a cast would be more than enough. It's going to be very unlikely that we have to alloca a data type bigger than ptrdiff_t anyway, let alone 8Mb.

@ibuclaw
Copy link
Member

ibuclaw commented Jul 29, 2018

This is the comment in relation to the alloca warning:

Let's not get too specific as to how large the limit
may be.  Someone's clearly an idiot when things
degrade into "if (N > Y) alloca(N)".

@ibuclaw
Copy link
Member

ibuclaw commented Jul 29, 2018

FYI: https://gcc.gnu.org/ml/gcc-patches/2018-07/msg01805.html

As for the druntime patch, I think there should be a limit applied on the size given to alloca(). If above that size just call malloc() instead with a scope(exit) free(ptr).

@belka-ew
Copy link
Contributor Author

Let us see what druntime people say. I'll try to prepare a PR during today.

@ibuclaw
Copy link
Member

ibuclaw commented Jul 30, 2018

Initially, gcc reviewers seem sceptical of moving alloca related warnings to common, so I guess will have to concede that point and move them here then.

D
; Documented in common.opt

Walloca-larger-than=
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might as well add all Walloca warning options and documentation.

Copy link
Member

@ibuclaw ibuclaw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is fine, just needs the following updates:

  1. Add Walloca, Walloca-larger-than= and Wno-alloca-larger-than to language options.
  2. Leave out druntime patch for now, on the promise that it will be dealt with upstream soon - it will be merged as soon as its in.

@belka-ew
Copy link
Contributor Author

belka-ew commented Aug 3, 2018

Add Walloca, Walloca-larger-than= and Wno-alloca-larger-than to language options.

Do I understand it correctly that Wno-alloca-larger-than shouldn't be explicitly in lang.opt and is supported automatically if Walloca-larger-than= is there?

Leave out druntime patch for now, on the promise that it will be dealt with upstream soon - it will be merged as soon as its in.

And add Wno-alloca-larger-than to the Makefiles again? Otherwise the build fails...

@belka-ew belka-ew changed the title Update to gcc-9-20180722 Update to gcc-9-20180729 Aug 3, 2018
@ibuclaw
Copy link
Member

ibuclaw commented Aug 3, 2018

Do I understand it correctly that Wno-alloca-larger-than shouldn't be explicitly in lang.opt and is supported automatically if Walloca-larger-than= is there?

These are all definitions in c.opt, they should be mirrored to make sure that no warnings about unsupported option happens. It also means that each would show up in --help=d too.

Walloca
D
; Documented in C

Walloca-larger-than=
D
; Documented in C

Wno-alloca-larger-than
D
; Documented in C

And add Wno-alloca-larger-than to the Makefiles again? Otherwise the build fails...

But we don't compile with --enable-werror for testing ?

@belka-ew
Copy link
Contributor Author

belka-ew commented Aug 3, 2018

These are all definitions in c.opt, they should be mirrored to make sure that no warnings about unsupported option happens. It also means that each would show up in --help=d too.

I used Wno-alloca-larger-than in the druntime Makefiles without defining it in lang.opt.

But we don't compile with --enable-werror for testing ?

Let's see :)

@ibuclaw
Copy link
Member

ibuclaw commented Aug 3, 2018

I don't believe it.

libphobos/configure:1426:  --enable-werror         turns on -Werror [default=yes]

It may be wiser to make that default=no as a default.

@belka-ew belka-ew closed this Aug 3, 2018
@belka-ew belka-ew reopened this Aug 3, 2018
@ibuclaw ibuclaw merged commit 7f86622 into D-Programming-GDC:master Aug 4, 2018
@belka-ew belka-ew deleted the gcc-9-20180722 branch August 4, 2018 08:32
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants