Patch from Samuel Thibault.
Change-Id: I782d6c702c086352a61df1574747bab0745ff545
Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/623415
Reviewed-by: Ian Lance Taylor <iant@google.com>
Reviewed-by: Cherry Mui <cherryyz@google.com>
Backport https://go.dev/cl/620955 from main repo. Original description:
src/runtime/testdata/testprogcgo/threadprof.go contains C code with a
variable called nullptr. This conflicts with the nullptr keyword in
the C23 revision of the C standard (showing up as gccgo test build
failures when updating GCC to use C23 by default when building C
code).
Rename that variable to nullpointer to avoid the clash with the
keyword (any other name that's not a keyword would work just as well).
Change-Id: I2e49fc87be16518215825f564bf5317eff4d4f3f
Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/621059
Reviewed-by: Cherry Mui <cherryyz@google.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
After CL 536643 passing NULL as the expected type permitted an untyped
constant expression to remain untyped. Change to passing the empty
interface type.
The panic and print/println functions are the only builtin functions
that turn an untyped constant expression into a regular function call,
and we already handled print/println specially.
The test case is https://go.dev/cl/603096.
Fixesgolang/go#68734
Change-Id: I02f353425b1f4cb8253ab7b29d707d93ede62f72
Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/603215
Reviewed-by: Than McIntosh <thanm@golang.org>
Reviewed-by: Cherry Mui <cherryyz@google.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
<stdbool.h> has been available since C99. Use it rather than defining
our own boolean type and values.
Fixes https://gcc.gnu.org/PR114875
Change-Id: I9feff55465edb20cbcabee0846aea9d7ac73a97b
Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/582275
Reviewed-by: Joedian Reid <joedian@google.com>
Reviewed-by: Tobias Klauser <tobias.klauser@gmail.com>
Reviewed-by: Than McIntosh <thanm@google.com>
As we move toward generics, the error messages need to be able
to refer to types in a readable manner. Add that capability,
and use it today in AST dumps.
Change-Id: I4284a7ce748276816dc8abec34c672747fd59875
Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/536716
Reviewed-by: Cherry Mui <cherryyz@google.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Otherwise we can't tell the difference between builtin type "any" and
a locally defined type "any".
This will require updates to the gccgo export data parsers in the main
Go repo and the x/tools repo. These updates are https://go.dev/cl/537195
and https://go.dev/cl/537215.
Change-Id: Ief043db22265d7e14b192fc4d3e1ef845b66c7fe
Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/536715
Reviewed-by: Cherry Mui <cherryyz@google.com>
Reviewed-by: David Chase <drchase@google.com>
It is no longer used. The iota value is now handled in the
determine-types pass.
Change-Id: I321802161f7d922dacaa2427da72e90c869e6f64
Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/536644
Reviewed-by: David Chase <drchase@google.com>
Reviewed-by: Than McIntosh <thanm@google.com>
Reviewed-by: Cherry Mui <cherryyz@google.com>
This change moves the lowering pass after the type determination and
the type checking passes. This lets us simplify some of the code that
determines the type of an expression, which previously had to work
correctly both before and after type determination.
I'm doing this to help with future generic support. For example, with
generics, we can see code like
func ident[T any](v T) T { return v }
func F() int32 {
s := int32(1)
return ident(s)
}
Before this change, we would type check return statements in the
lowering pass (see Return_statement::do_lower). With a generic
example like the above, that means we have to determine the type of s,
and use that to infer the type arguments passed to ident, and use that
to determine the result type of ident. That is too much to do at
lowering time. Of course we can change the way that return statements
work, but similar issues arise with index expressions, the types of
closures for function literals, and probably other cases as well.
Rather than try to deal with all those cases, we move the lowering
pass after type checking. This requires a bunch of changes, notably
for determining constant types. We have to add type checking for
various constructs that formerly disappeared in the lowering pass.
So it's a lot of shuffling. Sorry for the size of the patch.
Change-Id: Ic269e816f324c87feb708ca4cde0eff7f2f70c7b
Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/536643
Reviewed-by: Ian Lance Taylor <iant@google.com>
Reviewed-by: Than McIntosh <thanm@google.com>
This is a mechanical change to move Selector_expression up in expressions.cc.
This will make it visible to Builtin_call_expression for later work.
This produces a very large "git --diff", but "git diff --minimal" is clear.
Change-Id: I276355aa4d417b29e675077cc4d21153bdf9a980
Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/536642
Reviewed-by: Cherry Mui <cherryyz@google.com>
Reviewed-by: Than McIntosh <thanm@google.com>
This changes the Expression {numeric,string,boolean}_constant_value
methods non-const. This does not affect anything immediately,
but will be useful for later CLs in this series.
The only real effect is to Builtin_call_expression::do_export,
which remains const and can no longer call numeric_constant_value.
But it never needed to call it, as do_export runs after do_lower,
and do_lower replaces a constant expression with the actual constant.
Change-Id: I463dd0823bd811c482020ed67a1fdb794ae68253
Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/536641
Reviewed-by: Than McIntosh <thanm@google.com>
Reviewed-by: Cherry Mui <cherryyz@google.com>
This is a boilerplate change to pass gogo to Runtime::make_call.
It's not currently used but will be used by later CLs in this series.
Change-Id: I5319e9e8374fe9826624ca2ece8f76ce66be97d9
Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/536640
Reviewed-by: Than McIntosh <thanm@google.com>
Reviewed-by: David Chase <drchase@google.com>
Reviewed-by: Cherry Mui <cherryyz@google.com>
This method is not currently used by anything, but it will be used
by later CLs in this series.
Change-Id: Ia85e15782b0c12c9503fdf3601a9b84326bf3ea5
Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/536639
Reviewed-by: Than McIntosh <thanm@google.com>
Reviewed-by: Cherry Mui <cherryyz@google.com>
Reviewed-by: David Chase <drchase@google.com>
The gofrontend incorrectly accepted code that was missing a type conversion.
The test case for this is bug518.go in https://go.dev/cl/536537.
Future CLs in this series will detect the type error.
Change-Id: I1da941f97e32695b809f504ad448b1e4b66843e3
Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/536638
Reviewed-by: Cherry Mui <cherryyz@google.com>
Reviewed-by: Than McIntosh <thanm@google.com>
It's not used for anything.
Change-Id: I08afeaf2b2dee5f0c35893ad77f0a205f5475823
Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/536636
Reviewed-by: Than McIntosh <thanm@google.com>
Reviewed-by: Cherry Mui <cherryyz@google.com>
Also pass Gogo to the type verification pass.
This is a refactoring that does not change the compiler behavior.
This is in preparation for future CLs that rearrange the pass ordering.
This introduces one new call to go_get_gogo, which will be removed in
a future CL.
Change-Id: I361bafa0a78652b7c1ec8e6e5352508717453b15
Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/536635
Reviewed-by: Cherry Mui <cherryyz@google.com>
Reviewed-by: Than McIntosh <thanm@google.com>
Handle the AR environment variable, used by gccgo,
the same way we handle the CC environment variable.
This ports https://go.dev/cl/526275 to the gofrontend repo.
This is needed for gccgo testing because the top-level GCC Makefile
now passes a --plugin option to ar if it supports one.
Change-Id: I54cd6b6d5b1a757ea112c159414b2f24fa0fb25a
Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/526295
Reviewed-by: Than McIntosh <thanm@google.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
They are already collected via cmd/cgo.
The gccgo_link_c test is tweaked to do real linking as with this
change the cgo ldflags are not fully reflected in go build -n output,
since they now only come from the built archive.
This is a backport of https://go.dev/cl/497117 from the main repo.
For golang/go#60287
Change-Id: Ie0bf76b588724265d75dd9a96984dd6cc207f84e
Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/511675
Reviewed-by: Than McIntosh <thanm@google.com>
Reviewed-by: Cherry Mui <cherryyz@google.com>
In the Go 1.21 release the package internal/profile imports
internal/lazyregexp. That works when bootstrapping with Go 1.17,
because that compiler has internal/lazyregep and permits importing it.
We also have internal/lazyregexp in libgo, but since it is not installed
it is not available for importing. This CL adds internal/lazyregexp
to the list of internal packages that are installed for bootstrapping.
The Go 1.21, and earlier, releases have a couple of functions in
the internal/abi package that are always fully intrinsified.
The gofrontend recognizes and intrinsifies those functions as well.
However, the gofrontend was also building function descriptors
for references to the functions without calling them, which
failed because there was nothing to refer to. That is OK for the
gc compiler, which guarantees that the functions are only called,
not referenced. This CL arranges to not generate function descriptors
for these functions.
For golang/go#60913
Change-Id: I6a071e378205e5e90cfaebad23aca33dcfcef074
Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/504798
Reviewed-by: Cherry Mui <cherryyz@google.com>
Reviewed-by: Than McIntosh <thanm@google.com>
The final argument to mmap, of type off_t, varies.
In CL 445375 we changed it to always use the C off_t type,
but that broke 32-bit big-endian Linux systems. On those systems,
using the C off_t type requires calling the mmap64 function.
In C this is automatically handled by the <sys/mman.h> file.
In Go, we would have to change the magic //extern comment to
call mmap64 when appropriate. Rather than try to get that right,
we instead go through a C function that uses C implicit type
conversions to pick the right type.
Fixes https://gcc.gnu.org/PR110297
Change-Id: Id54ece0c64601c060e335e96e6b76f4d5f002ae8
Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/504415
Reviewed-by: Ian Lance Taylor <iant@google.com>
Reviewed-by: Cherry Mui <cherryyz@google.com>
In CL 384695 I simplified the code that built lists of benchmarks,
examples, and fuzz tests, and managed to break it. This CL corrects
the code to once again make the benchmarks available, and to run
the examples with output and the fuzz targets.
Doing this revealed a test failure in internal/fuzz on 32-bit x86:
a signalling NaN is turned into a quiet NaN on the 387 floating-point
stack that GCC uses by default. This CL skips the test.
Fixesgolang/go#60826
Change-Id: I103669e11fe2c03c8c824a96d19cc459c47464ee
Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/503798
Reviewed-by: Cherry Mui <cherryyz@google.com>
Reviewed-by: Than McIntosh <thanm@google.com>
Backport CL 421442 from upstream.
Original description:
Arrange for tests that call setMimeInit to fully restore the old values,
by clearing the sync.Once that controls initialization.
Once we've done that, call initMime in initMimeUnixTest because
otherwise the test types loaded there will be cleared by the call to
initMime that previously was not being done.
For golang/go#51648
Change-Id: Ie21bb1e891479d2d842e831dc5225a9386ec6ef1
Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/483117
Reviewed-by: Than McIntosh <thanm@google.com>
Reviewed-by: Cherry Mui <cherryyz@google.com>
In https://go.dev/cl/343873 we stopped padding zero-sized trailing
fields in functions that return multiple results where the last result
is zero-sized. This CL makes the corresponding change on the caller side.
The test case is https://go.dev/cl/479898.
Fixesgolang/go#55242
Change-Id: I1270051ef7e4b4a20c1aa7a7fba16e0604e932ca
Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/479955
Reviewed-by: Ian Lance Taylor <iant@google.com>
Reviewed-by: Cherry Mui <cherryyz@google.com>
This avoids clang warnings:
gcc/go/gofrontend/escape.cc:1290:17: warning: private field 'fn_' is not used [-Wunused-private-field]
gcc/go/gofrontend/escape.cc:3478:19: warning: private field 'context_' is not used [-Wunused-private-field]
gcc/go/gofrontend/lex.h:564:15: warning: private field 'input_file_name_' is not used [-Wunused-private-field]
gcc/go/gofrontend/types.cc:5788:20: warning: private field 'call_' is not used [-Wunused-private-field]
gcc/go/gofrontend/wb.cc:206:9: warning: private field 'gogo_' is not used [-Wunused-private-field]
Path by Martin Liška.
Change-Id: I3c1721b26454ba4811991f1e4272918c9bd24421
Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/458975
Reviewed-by: Cherry Mui <cherryyz@google.com>
Reviewed-by: Than McIntosh <thanm@google.com>
The current version is the same as for the previous GCC release,
but there have been minor changes like new type descriptors that
make it impossible to run Go programs built with the previous GCC
release with the current libgo.
Fixes https://gcc.gnu.org/PR108057
Change-Id: I4e226b5d2c64e04accf859b3442b08f0207ba9be
Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/456976
Reviewed-by: Than McIntosh <thanm@google.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Change-Id: Icb130bb38daac1a215309f1208fa42d02192381c
Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/454275
Reviewed-by: Than McIntosh <thanm@google.com>
Reviewed-by: Cherry Mui <cherryyz@google.com>
TryBot-Bypass: Ian Lance Taylor <iant@golang.org>
This does the right thing for either glibc or musl on GNU/Linux.
Based on patch by Sören Tempel.
Change-Id: If2969e131f0fae456d58b35d839d8abe191fcc59
Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/454176
Reviewed-by: Cherry Mui <cherryyz@google.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
TryBot-Bypass: Ian Lance Taylor <iant@google.com>
The last argument to the C mmap function is type off_t, not uintptr.
On some 32-bit systems, off_t is larger than uintptr.
Based on patch by Sören Tempel.
Change-Id: Ib6f9d5bcd4734f99a72889e2282b97ec3c8fbd34
Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/445735
Reviewed-by: Cherry Mui <cherryyz@google.com>
Reviewed-by: Than McIntosh <thanm@google.com>
The compiler neglected to notice that a conversion from a string
constant to a string type was a valid string constant.
No test case because this only caused a compiler failure when compiling
without optimization, which is not the normal case, and is not a case
that we test.
Fixesgolang/go#56113
Change-Id: I99f8f2b91db73b8cb07f415267a9bf2154e1ab54
Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/441555
Reviewed-by: Cherry Mui <cherryyz@google.com>
Reviewed-by: Than McIntosh <thanm@google.com>
Instead of building the thunk struct type in the determine_types pass,
build it when we need it. That ensures that we are consistent in
determining whether an argument is constant.
We no longer need to add a field for a call to recover, as the
simplify_thunk_statements pass runs after the build_recover_thunks pass,
so the additional argument will already have been added to the call.
The test case is https://go.dev/cl/440297.
Fixesgolang/go#56109
Change-Id: I7e2271cf8dc2ed523a4e9cb22728daa773daaa90
Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/440298
Reviewed-by: Cherry Mui <cherryyz@google.com>
Reviewed-by: Than McIntosh <thanm@google.com>
Tighten up the argument type checking for Builtin_call_expression to
catch erroneous cases such as
panic(panic("bad")))
where an argument void type is being passed to panic/alignof/sizeof.
Fixesgolang/go#56071.
Change-Id: I25e28fad724c959e738103141fdf9885e0dd4dd5
Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/439815
Reviewed-by: Cherry Mui <cherryyz@google.com>
Previously, libgo relied on the _sigev_un implementation-specific
field in struct sigevent, which is only available on glibc.
This patch uses the sigev_notify_thread_id macro instead which is
mandated by timer_create(2). In theory, this should work with any libc
implementation for Linux. Unfortunately, there is an open glibc bug
as glibc does not define this macro. For this reason, a glibc-specific
workaround is required. Other libcs (such as musl) define the macro
and don't require the workaround.
See https://sourceware.org/bugzilla/show_bug.cgi?id=27417
This makes libgo compatible with musl libc.
Based on patch by Sören Tempel.
Change-Id: I0924a53d5212730ebc395ecf9199f85967be8cc6
Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/434755
Reviewed-by: Cherry Mui <cherryyz@google.com>
Reviewed-by: Than McIntosh <thanm@google.com>
In GCCGO and gollvm, the logic for allocating one byte for the last field is:
1. the last field has zero size
2. the struct itself does not have zero size
3. the last field is not blank
this commit adds the last two conditions to runtime.structToFFI.
For golang/go#55146
Change-Id: Iabc3ee09e7f14fab037fd197a9658b099c419904
Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/431735
Reviewed-by: Ian Lance Taylor <iant@google.com>
Reviewed-by: Cherry Mui <cherryyz@google.com>
This ports https://go.dev/cl/421879 to libgo. This is a quick port to
update gofrontend to work with the version of cgo in gc mainline.
A more complete port will follow, changing the gc version of cmd/cgo to
choose an approach based on feature testing the gccgo in use.
Updates golang/go#46731
Change-Id: I61d1f97781ac1aeb5f8a51ddeb1db378d8c97f95
Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/432338
Reviewed-by: Than McIntosh <thanm@google.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
We were ignoring all functions starting with "__morestack_", but not
the function "__morestack" itself. Without this change, some tests
such as recover.go started failing recently, though I'm not sure
exactly what changed.
Change-Id: I8a00f6e7b303f338ddde269b16aed0b3ede7a478
Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/427935
Reviewed-by: Cherry Mui <cherryyz@google.com>
Reviewed-by: Than McIntosh <thanm@google.com>
Musl defines SYS_timer_settime32, not SYS_timer_settime, on 32-bit systems.
Based on patch by Sören Tempel.
Change-Id: I1f3485028d132ceca1aba595325af24b4d72b894
Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/420222
Reviewed-by: Ian Lance Taylor <iant@google.com>
Reviewed-by: Cherry Mui <cherryyz@google.com>