aboutsummaryrefslogtreecommitdiff
path: root/gcc/go/gofrontend/expressions.cc
AgeCommit message (Collapse)AuthorFilesLines
2023-06-23compiler, libgo: support bootstrapping gc compilerIan Lance Taylor1-1/+2
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 Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/504798
2023-06-21compiler: determine types of Slice_{value,info} expressionsIan Lance Taylor1-0/+10
This fixes an accidental omission in the determine types pass. Test case is https://go.dev/cl/505015. Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/504797
2023-03-28compiler: mark Call_expression multiple results as a result structIan Lance Taylor1-0/+1
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. Fixes golang/go#55242 Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/479955
2022-12-22compiler: remove unused fieldsIan Lance Taylor1-1/+1
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. Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/458975
2022-10-10compiler: treat S("") as a string constantIan Lance Taylor1-0/+3
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. Fixes golang/go#56113 Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/441555
2022-10-06compiler: better arg type checking for selected builtinsThan McIntosh1-1/+6
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. Fixes golang/go#56071. Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/439815
2022-07-05compiler: propagate array length error marker fartherIan Lance Taylor1-0/+6
Fixes golang/go#53639 Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/415936
2022-06-29compiler: check repeated const expressions in new scopeIan Lance Taylor1-91/+19
Test case is const8.go in https://go.dev/cl/414795. Fixes golang/go#53585 Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/414914
2022-06-28compiler: permit expressions of abstract bool to remain abstractIan Lance Taylor1-4/+5
Test case is https://go.dev/cl/414755. Fixes golang/go#51475 Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/414735
2022-06-27compiler: don't use sink as parameter in method expression thunkIan Lance Taylor1-2/+7
Also fix a couple of cases where the error led to a later compiler crash. Test case is https://go.dev/cl/414336. Fixes golang/go#52871 Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/414354
2022-06-27compiler: always initialize mpfr in integer importIan Lance Taylor1-1/+1
Test case is https://go.dev/cl/413980. Fixes golang/go#52862 Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/413981
2022-05-06compiler: remove Array_index_expression::is_lvalue_Ian Lance Taylor1-8/+5
As of CL 77510 it is never true. Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/394695
2022-05-06compiler: error for duplicate bool map keysIan Lance Taylor1-0/+16
For golang/go#35945 Fixes golang/go#28104 Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/403954
2022-02-09compiler: don't warn for print()Ian Lance Taylor1-10/+1
We used to warn for calls to print(), because it doesn't do anything. However, a Go 1.18 test uses that call, and it is valid Go. Change the compiler to just accept it and compile it; this will produce calls to printlock and printunlock, and nothing else. Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/384355
2022-02-09compiler: use nil pointer for zero length string constantIan Lance Taylor1-3/+9
We used to pointlessly set the pointer of a zero length string constant to point to a zero byte constant. Instead, just use nil. Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/384354
2022-02-08compiler: recognize Go 1.18 runtime/internal/atomic methodsIan Lance Taylor1-1/+155
The Go 1.18 library introduces specific types in runtime/internal/atomic. Recognize and optimize the methods on those types, as we do with the functions in runtime/internal/atomic. While we're here avoid getting confused by methods in any other package that we recognize specially. * go-gcc.cc (Gcc_backend::Gcc_backend): Define builtins __atomic_load_1 and __atomic_store_1. Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/383654
2022-02-08compiler, internal/abi: implement FuncPCABI0, FuncPCABIInternalIan Lance Taylor1-0/+44
The Go 1.18 standard library uses an internal/abi package with two functions that are implemented in the compiler. This patch implements them in the gofrontend, to support the upcoming update to 1.18. Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/383514
2021-11-11compiler: traverse func subexprs when creating func descriptorsIan Lance Taylor1-10/+47
Fix the Create_func_descriptors pass to traverse the subexpressions of the function in a Call_expression. There are no subexpressions in the normal case of calling a function a method directly, but there are subexpressions when in code like F().M() when F returns an interface type. Forgetting to traverse the function subexpressions was almost entirely hidden by the fact that we also created the necessary thunks in Bound_method_expression::do_flatten and Interface_field_reference_expression::do_get_backend. However, when the thunks were created there, they did not go through the order_evaluations pass. This almost always worked, but failed in the case in which the function being thunked returned multiple results, as order_evaluations takes the necessary step of moving the Call_expression into its own statement, and that would not happen when order_evaluations was not called. Avoid hiding errors like this by changing those methods to only lookup the previously created thunk, rather than creating it if it was not already created. The test case for this is https://golang.org/cl/363156. Fixes https://golang.org/issue/49512 Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/363274
2021-09-10compiler: correct condition for calling memclrHasPointersIan Lance Taylor1-1/+1
When compiling append(s, make([]typ, ln)...), where typ has a pointer, and the append fits within the existing capacity of s, the condition used to clear out the new elements was reversed. Fixes golang/go#47771 Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/344189
2021-08-12compiler: store pointers to go:notinheap types indirectlyIan Lance Taylor1-7/+23
This is the gofrontend version of https://golang.org/cl/264480. For golang/go#42076 Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/340609
2021-08-10compiler: don't crash on a, b := int(0)Ian Lance Taylor1-2/+13
Fixes PR go/101851 Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/341330
2021-08-07compiler: support export/import of unsafe.Add/SliceIan Lance Taylor1-0/+8
For golang/go#19367 For golang/go#40481 Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/340549
2021-08-05runtime: extend internal atomics to comply with sync/atomicIan Lance Taylor1-25/+23
This is the gofrontend version of https://golang.org/cl/289152. Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/339690
2021-08-03compiler: support new language constructs in escape analysisCherry Mui1-43/+1
Previous CLs add new language constructs in Go 1.17, specifically, unsafe.Add, unsafe.Slice, and conversion from a slice to a pointer to an array. This CL handles them in the escape analysis. At the point of the escape analysis, unsafe.Add and unsafe.Slice are still builtin calls, so just handle them in data flow. Conversion from a slice to a pointer to an array has already been lowered to a combination of compound expression, conditional expression and slice info expressions, so handle them in the escape analysis. Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/339671
2021-08-03compiler: check slice to pointer-to-array conversion element typeIan Lance Taylor1-1/+4
When checking a slice to pointer-to-array conversion, I forgot to verify that the elements types are identical. For golang/go#395 Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/339329
2021-08-02compiler, runtime: allow slice to array pointer conversionIan Lance Taylor1-2/+51
Panic if the slice is too short. For golang/go#395 Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/338630
2021-08-02compiler, runtime: support unsafe.Add and unsafe.SliceIan Lance Taylor1-0/+227
For golang/go#19367 For golang/go#40481 Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/338949
2021-06-29compiler: don't generate temporaries for composite literalsIan Lance Taylor1-97/+6
We were generating temporaries for composite literals when a conversion to interface type was required. However, Cherry's https://golang.org/cl/176459 changed the compiler to insert explicit type conversions. And those explicit type conversions insert the required temporaries in Type_conversion_expression::do_flatten. So in practice the composite literal do_flatten methods would never insert temporaries, as the values they see would always be multi_eval_safe. So just remove the unnecessary do_flatten methods. Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/331691
2021-06-29compiler: in composite literals use temps only for interfacesIan Lance Taylor1-4/+13
For a composite literal we only need to introduce a temporary variable if we may be converting to an interface type, so only do it then. This saves over 80% of compilation time when using gccgo to compile cmd/internal/obj/x86, as the GCC middle-end spends a lot of time pointlessly computing interactions between temporary variables. For PR debug/101064 For golang/go#46600 Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/331513
2021-05-24compiler: mark global variables whose address is takenIan Lance Taylor1-25/+38
To implement this, change the backend to use flag bits for variables. Fixes https://gcc.gnu.org/PR100537 PR go/100537 * go-gcc.cc (class Gcc_backend): Update methods that create variables to take a flags parameter. Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/322129
2021-03-17compiler: copy receiver argument for go/defer of method callIan Lance Taylor1-1/+1
Test case is https://golang.org/cl/302371. Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/302270
2021-03-11compiler: create temporaries for heap variablesIan Lance Taylor1-49/+87
The compiler generally doesn't create a temporary for an expression that is a variable, because it's normally valid to simply reload the value from the variable. However, if the variable is in the heap, then loading the value is a pointer indirection. The process of creating GCC IR can cause the variable load and the pointer indirection to be split, such that the second evaluation only does the pointer indirection. If there are conditionals in between the two uses, this can cause the second use to load the pointer from an uninitialized register. Avoid this by introducing a new Expression method that returns whether it is safe to evaluate an expression multiple times, and use it everywhere. The test case is https://golang.org/cl/300789. Fixes golang/go#44383 Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/300809
2020-12-23compiler: nil-checked pointers and index expressions can trapIan Lance Taylor1-6/+4
The compiler was treating indirections through pointers that had been explicitly checked against nil and slice and string index expressions as non-trapping memory references. That is true for ordinary Go programs, but it isn't true if the programs construct their own memory addresses. In particular it isn't true for the kinds of programs that want to use runtime.SetPanicOnFault. The effect of this will be slightly larger binaries, due to additional exception information, and perhaps slightly less optimization. Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/279960
2020-12-15compiler: avoid knock-on errors from invalid interfacesIan Lance Taylor1-3/+20
The test case for this is issue11614.go. Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/278192
2020-12-08compiler: use correct location for iota errorsIan Lance Taylor1-9/+82
Also check for valid array length when reducing len/cap to a constant. For golang/go#8183 Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/275654
2020-12-07compiler: type of string index expression is byteIan Lance Taylor1-2/+2
To make this work from the do_type method, add "byte" and "rune" to the list of known integer types, and look them up that way rather than via gogo->lookup_global. For golang/go#8745 Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/275653
2020-12-03compiler: cast comparison function result to expected bool typeIan Lance Taylor1-3/+39
Otherwise cases like type mybool bool var b mybool = [10]string{} == [10]string{} get an incorrect type checking error. Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/274446
2020-12-03compiler: defer to middle-end for complex divisionIan Lance Taylor1-21/+0
Go used to use slightly different semantics than C99 for complex division, so we used runtime routines to handle the different. The gc compiler has changes its behavior to match C99, so changes ours as well. For golang/go#14644 Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/274213
2020-11-30compiler, runtime: check len/cap for append(s, make(T, l)...)Ian Lance Taylor1-22/+13
The overflow checks done in growslice always reported an error for the capacity argument, even if it was the length argument that overflowed. This change lets the code pass the current issue4085b.go test. Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/273806
2020-11-30compiler: always use int context for index valuesIan Lance Taylor1-26/+5
For golang/go#14844 Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/273889
2020-11-28compiler: avoid follow-on errors for bad typesIan Lance Taylor1-1/+38
Mark bad types as erroneous, to avoid generating further errors. This required some code using array types to check for errors. For https://golang.org/issue/19880 Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/273626
2020-11-25compiler: avoid silent truncation for string(1 << 32)Ian Lance Taylor1-1/+9
In the conversion of a constant integer to a string type, the value of the constant integer was being silently truncated from unsigned long to unsigned int, producing the wrong string value. Add an explicit overflow check to avoid this problem. For golang/go#42790 Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/272611
2020-11-20compiler, libgo: change mangling schemeIan Lance Taylor1-20/+18
Overhaul the mangling scheme to avoid ambiguities if the package path contains a dot. Instead of using dot both to separate components and to mangle characters, use dot only to separate components and use underscore to mangle characters. For golang/go#41862 Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/271726
2020-10-15compiler: export type for string and bool constantsIan Lance Taylor1-38/+44
Also consolidate the identical code for constant type export into a pair of static methods. Fixes golang/go#35739 Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/262437
2020-09-21compiler: finalize methods for type aliases of struct typesIan Lance Taylor1-20/+30
Previously we would finalize the methods of the alias type itself, but since its a type alias we really need to finalize the methods of the aliased type. Also, handle method expressions of unnamed struct types. Test case is https://golang.org/cl/251168. Fixes golang/go#38125 Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/251279
2020-08-17compiler: export thunks referenced by inline functionsIan Lance Taylor1-5/+4
The test case is https://golang.org/cl/248637. Fixes golang/go#40252 Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/248638
2020-08-10runtime: revert eqtype for AIXClément Chigot1-8/+19
AIX linker is not able to merge identical type descriptors in a single symbol if there are coming from different object or shared object files. This results into several pointers referencing the same type descriptors. Thus, eqtype is needed to ensure that these different symbols will be considered as the same type descriptor. Fixes golang/go#39276 gcc/go/ChangeLog: * go-c.h (struct go_create_gogo_args): Add need_eqtype field. * go-lang.c (go_langhook_init): Set need_eqtype. Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/235697
2020-08-04compiler: delete lowered constant stringsIan Lance Taylor1-1/+8
If we lower a constant string operation in a Binary_expression, delete the strings. This is safe because constant strings are always newly allocated. This is a hack to use much less memory when compiling the new time/tzdata package, which has a file that contains the sum of over 13,000 constant strings. We don't do this for numeric expressions because that could cause us to delete an Iota_expression. We should have a cleaner approach to memory usage some day. Fixes PR go/96450
2020-07-27compiler,runtime: pass only ptr and len to some runtime callsIan Lance Taylor1-27/+33
This ports https://golang.org/cl/227163 to the Go frontend. This is a step toward moving up to the go1.15rc1 release. Original CL description: cmd/compile,runtime: pass only ptr and len to some runtime calls Some runtime calls accept a slice, but only use ptr and len. This change modifies most such routines to accept only ptr and len. After this change, the only runtime calls that accept an unnecessary cap arg are concatstrings and slicerunetostring. Neither is particularly common, and both are complicated to modify. Negligible compiler performance impact. Shrinks binaries a little. There are only a few regressions; the one I investigated was due to register allocation fluctuation. Passes 'go test -race std cmd', modulo golang/go#38265 and golang/go#38266. Wow, does that take a long time to run. file before after Δ % compile 19655024 19655152 +128 +0.001% cover 5244840 5236648 -8192 -0.156% dist 3662376 3658280 -4096 -0.112% link 6680056 6675960 -4096 -0.061% pprof 14789844 14777556 -12288 -0.083% test2json 2824744 2820648 -4096 -0.145% trace 11647876 11639684 -8192 -0.070% vet 8260472 8256376 -4096 -0.050% total 115163736 115118808 -44928 -0.039% For golang/go#36890 Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/245099
2020-07-11compiler: avoid generating unnamed bool type descriptorIan Lance Taylor1-4/+1
We were generating it in cases where a boolean expression was converted directly to an empty interface type. Fixes golang/go#40152 Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/242002