mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
Conflicts: - src/cmd/compile/internal/ir/symtab.go - src/cmd/compile/internal/ssa/prove.go - src/cmd/compile/internal/ssa/rewriteAMD64.go - src/cmd/compile/internal/ssagen/intrinsics.go - src/cmd/compile/internal/typecheck/builtin.go - src/internal/buildcfg/exp.go - src/internal/strconv/ftoa.go - test/codegen/stack.go Manually resolved some conflicts: - Use internal/strconv for simd.String, remove internal/ftoa - prove.go is just copied from the one on the main branch. We have cherry-picked the changes to prove.go to main branch, so our copy is identical to an old version of the one on the main branch. There are CLs landed after our cherry-picks. Just copy it over to adopt the new code. Merge List: + 2025-11-1357362e9814go/types, types2: check for direct cycles as a separate phase + 2025-11-13099e0027bdcmd/go/internal/modfetch: consolidate global vars + 2025-11-13028375323fcmd/go/internal/modfetch/codehost: fix flaky TestReadZip + 2025-11-134ebf295b0bruntime: prefer to restart Ps on the same M after STW + 2025-11-13625d8e9b9cruntime/pprof: fix goroutine leak profile tests for noopt + 2025-11-134684a26c26spec: remove cycle restriction for type parameters + 2025-11-130f9c8fb29dcmd/asm,cmd/internal/obj/riscv: add support for riscv compressed instructions + 2025-11-13a15d036ce2cmd/internal/obj/riscv: implement better bit pattern encoding + 2025-11-12abb241a789cmd/internal/obj/loong64: add {,X}VS{ADD,SUB}.{B/H/W/V}{,U} instructions support + 2025-11-120929d21978cmd/go: keep objects alive while stopping cleanups + 2025-11-12f03d06ec1aruntime: fix list test memory management for mayMoreStack + 2025-11-1248127f656bcrypto/internal/fips140/sha3: remove outdated TODO + 2025-11-12c3d1d42764sync/atomic: amend comments for Value.{Swap,CompareAndSwap} + 2025-11-12e0807ba470cmd/compile: don't clear ptrmask in fillptrmask + 2025-11-1266318d2b4binternal/abi: correctly describe result in Name.Name doc comment + 2025-11-1234aef89366cmd/compile: use FCLASSD for subnormal checks on riscv64 + 2025-11-120c28789bd7net/url: disallow raw IPv6 addresses in host + 2025-11-124e761b9a18cmd/compile: optimize liveness in stackalloc + 2025-11-12956909ff84crypto/x509: move BetterTLS suite from crypto/tls + 2025-11-126525f46707cmd/link: change shdr and phdr from arrays to slices + 2025-11-12d3aeba1670runtime: switch p.gcFractionalMarkTime to atomic.Int64 + 2025-11-128873e8bea2runtime,runtime/pprof: clean up goroutine leak profile writing + 2025-11-12b8b84b789ecmd/go: clarify the -o testflag is only for copying the binary + 2025-11-12c761b26b56mime: parse media types that contain braces + 2025-11-1265858a146eos/exec: include Cmd.Start in the list of methods that run Cmd + 2025-11-114bfc3a9d14std,cmd: go fix -any std cmd + 2025-11-112263d4aabdruntime: doubly-linked sched.midle list + 2025-11-11046dce0e54runtime: use new list type for spanSPMCs + 2025-11-115f11275457runtime: reusable intrusive doubly-linked list + 2025-11-11951cf0501binternal/trace/testtrace: fix flag name typos + 2025-11-112750f95291cmd/go: implement accurate pseudo-versions for Mercurial + 2025-11-11b709a3e8b4cmd/go/internal/vcweb: cache hg servers + 2025-11-11426ef30ecfcmd/go: implement -reuse for Mercurial repos + 2025-11-105241d114f5spec: more precise prose for special case of append + 2025-11-10cdf64106f6go/types, types2: first argument to append must never be be nil + 2025-11-10a0eb4548cf.gitignore: ignore go test artifacts + 2025-11-10bf58e7845einternal/trace: add "command" to convert text traces to raw + 2025-11-10052c192a4cruntime: fix lock rank for work.spanSPMCs.lock + 2025-11-10bc5ffe5c79internal/runtime/sys,math/bits: eliminate bounds checks on len8tab + 2025-11-1032f8d6486fruntime: document that tracefpunwindoff applies to some profilers + 2025-11-101c1c1942bacmd/go: remove redundant AVX regex in security flag checks + 2025-11-103b3d6b9e5dcmd/internal/obj/arm64: shorten constant integer loads + 2025-11-105f4b5f1a19runtime/msan: use different msan routine for copying + 2025-11-100fe6c8e8c8runtime: tweak wording for comment of mcache.flushGen + 2025-11-1095a0e5adc1sync: don't call Done when f() panics in WaitGroup.Go + 2025-11-08e8ed85d6c2cmd/go: update goSum if necessary + 2025-11-08b76103c08ecmd/go: output missing GoDebug entries + 2025-11-0747a63a331dcmd/go: rewrite hgrepo1 test repo to be deterministic + 2025-11-077995751d3acmd/go: copy git reuse and support repos to hg + 2025-11-0766c7ca7fb3cmd/go: improve TestScript/reuse_git + 2025-11-07de84ac55c6cmd/link: clean up some comments to Go standards + 2025-11-075cd1b73772runtime: correctly print panics before fatal-ing on defer + 2025-11-0791ca80f970runtime/cgo: improve error messages after pointer panic + 2025-11-07d36e88f21fruntime: tweak wording for doc + 2025-11-06ad3ccd92e4cmd/link: move pclntab out of relro section + 2025-11-0643b91e7abditer: fix a tiny doc comment bug + 2025-11-0648c7fa13c6Revert "runtime: remove the pc field of _defer struct" + 2025-11-058111104a21cmd/internal/obj/loong64: add {,X}VSHUF.{B/H/W/V} instructions support + 2025-11-052e2072561ccmd/internal/obj/loong64: add {,X}VEXTRINS.{B,H,W,V} instruction support + 2025-11-0501c29d1f0binternal/chacha8rand: replace VORV with instruction VMOVQ on loong64 + 2025-11-05f01a1841fdcmd/compile: fix error message on loong64 + 2025-11-058cf7a0b4c9cmd/link: support weak binding on darwin + 2025-11-052dd7e94e16cmd/go: use go.dev instead of golang.org in flag errors + 2025-11-0528f1ad5782cmd/go: fix TestScript/govcs + 2025-11-05daa220a1c9cmd/go: silence TLS handshake errors during test + 2025-11-053ae9e95002cmd/go: fix TestCgoPkgConfig on darwin with pkg-config installed + 2025-11-05a494a26bc2cmd/go: fix TestScript/vet_flags + 2025-11-05a8fb94969ccmd/go: fix TestScript/tool_build_as_needed + 2025-11-0504f05219c4cmd/cgo: skip escape checks if call site has no argument + 2025-11-049f3a108ee0os: ignore O_TRUNC errors on named pipes and terminal devices on Windows + 2025-11-040e1bd8b5f1cmd/link, runtime: don't store text start in pcHeader + 2025-11-047347b54727cmd/link: don't generate .gosymtab section + 2025-11-046914dd11c0cmd/link: add and use new SymKind SFirstUnallocated + 2025-11-04f5f14262d0cmd/link: remove misleading comment + 2025-11-0461de3a9daecmd/link: remove unused SFILEPATH symbol kind + 2025-11-048e2bd267b5cmd/link: add comments for SymKind values + 2025-11-0416705b962ecmd/compile: faster liveness analysis in regalloc + 2025-11-04a5fe6791d7internal/syscall/windows: fix ReOpenFile sentinel error value + 2025-11-04a7d174ccaacmd/compile/internal/ssa: simplify riscv64 FCLASSD rewrite rules + 2025-11-04856238615druntime: amend doc for setPinned + 2025-11-04c7ccbddf22cmd/compile/internal/ssa: more aggressive on dead auto elim + 2025-11-0475b2bb1d1acmd/cgo: drop pre-1.18 support + 2025-11-04dd839f1d00internal/strconv: handle %f with fixedFtoa when possible + 2025-11-046e165b4d17cmd/compile: implement Avg64u, Hmul64, Hmul64u for wasm + 2025-11-049f6590f333encoding/pem: don't reslice in failure modes + 2025-11-0334fec512ceinternal/strconv: extract fixed-precision ftoa from ftoaryu.go + 2025-11-03162ba6cc40internal/strconv: add tests and benchmarks for ftoaFixed + 2025-11-039795c7ba22internal/strconv: fix pow10 off-by-one in exponent result + 2025-11-03ad5e941a45cmd/internal/obj/loong64: using {xv,v}slli.d to perform copying between vector registers + 2025-11-03dadbac0c9ecmd/internal/obj/loong64: add VPERMI.W, XVPERMI.{W,V,Q} instruction support + 2025-11-03e2c6a2024cruntime: avoid append in printint, printuint + 2025-11-03c93cc603cdruntime: allow Stack to traceback goroutines in syscall _Grunning window + 2025-11-03b5353fd90aruntime: don't panic in castogscanstatus + 2025-11-0343491f8d52cmd/cgo: use the export'ed file/line in error messages + 2025-11-03aa94fdf0cccmd/go: link to go.dev/doc/godebug for removed GODEBUG settings + 2025-11-034d2b03d2fccrypto/tls: add BetterTLS test coverage + 2025-11-030c4444e13dcmd/internal/obj: support arm64 FMOVQ large offset encoding + 2025-11-0385bec791a0cmd/go/testdata/script: loosen list_empty_importpath for freebsd + 2025-11-0317b57078abinternal/runtime/cgobench: add cgo callback benchmark + 2025-11-035f8fdb720ccmd/go: move functions to methods + 2025-11-030a95856b95cmd/go: eliminate additional global variable + 2025-11-03f93186fb44cmd/go/internal/telemetrystats: count cgo usage + 2025-11-03eaf28a27fdruntime: update outdated comments for deferprocStack + 2025-11-03e12d8a90bfall: remove extra space in the comments + 2025-11-03c5559344acinternal/profile: optimize Parse allocs + 2025-11-035132158ac2bytes: add Buffer.Peek + 2025-11-03361d51a6b5runtime: remove the pc field of _defer struct + 2025-11-0300ee1860cecrypto/internal/constanttime: expose intrinsics to the FIPS 140-3 packages + 2025-11-02388c41c412cmd/go: skip git sha256 tests if git < 2.29 + 2025-11-01385dc33250runtime: prevent time.Timer.Reset(0) from deadlocking testing/synctest tests + 2025-10-3199b724f454cmd/go: document purego convention + 2025-10-3127937289dcruntime: avoid zeroing scavenged memory + 2025-10-3089dee70484runtime: prioritize panic output over racefini + 2025-10-308683bb846druntime: optimistically CAS atomicstatus directly in enter/exitsyscall + 2025-10-305b8e850340runtime: don't track scheduling latency for _Grunning <-> _Gsyscall + 2025-10-30251814e580runtime: document tracer invariants explicitly + 2025-10-307244e9221fruntime: eliminate _Psyscall + 2025-10-305ef19c0d0cstrconv: delete divmod1e9 + 2025-10-30d32b1f02c3runtime: delete timediv + 2025-10-30cbbd385cb8strconv: remove arch-specific decision in formatBase10 + 2025-10-306aca04a73areflect: correct internal docs for uncommonType + 2025-10-30235b4e729dcmd/compile/internal/ssa: model right shift more precisely + 2025-10-30d44db293f9go/token: fix a typo in a comment + 2025-10-30cdc6b559castrconv: remove hand-written divide on 32-bit systems + 2025-10-301e5bb416d8cmd/compile: implement bits.Mul64 on 32-bit systems + 2025-10-3038317c44e7crypto/internal/fips140/aes: fix CTR generator + 2025-10-293be9a0e014go/types, types: proceed with correct (invalid) type in case of a selector error + 2025-10-29d2c5fa0814strconv: remove &0xFF trick in formatBase10 + 2025-10-299bbda7c99dcmd/compile: make prove understand div, mod better + 2025-10-29915c1839fetest/codegen: simplify asmcheck pattern matching + 2025-10-2932ee3f3f73runtime: tweak example code for gorecover + 2025-10-29da3fb90b23crypto/internal/fips140/bigmod: fix extendedGCD comment + 2025-10-299035f7aea5runtime: use internal/strconv + 2025-10-2949c1da474dinternal/itoa, internal/runtime/strconv: delete + 2025-10-29b2a346bbd1strconv: move all but Quote to internal/strconv + 2025-10-28041f564b3einternal/runtime/gc/scan: avoid memory destination on VPCOMPRESSQ + 2025-10-2881afd3a59bcmd/compile: extend ppc64 MADDLD to match const ADDconst & MULLDconst + 2025-10-28ea50d61b66cmd/compile: name change isDirect -> isDirectAndComparable + 2025-10-28bd4dc413cdcmd/compile: don't optimize away a panicing interface comparison + 2025-10-2830c047d0d0cmd/compile: extend loong MOV*idx rules to match ADDshiftLLV + 2025-10-2846e5e2b09aruntime: define PanicBounds in funcdata.h + 2025-10-283da0356685crypto/internal/fips140test: collect 300M entropy samples for ESV + 2025-10-28d5953185d5runtime: amend comments a bit + 2025-10-2812c8d14d94errors: document that the target of Is must be comparable + 2025-10-281f4d14e493go/types, types2: pull up package-level object sort to a separate phase + 2025-10-28b8aa1ee442go/types, types2: reduce locks held at once in resolveUnderlying + 2025-10-2824af441437cmd/compile: rewrite proved multiplies by 0 or 1 into CondSelect + 2025-10-282d33a456c6cmd/compile: move branchelim supported arches to Config + 2025-10-272c91c33e88crypto/subtle,cmd/compile: add intrinsics for ConstantTimeSelect and *Eq + 2025-10-2773d7635faecmd/compile: add generic rules to remove bool → int → bool roundtrips + 2025-10-271662d55247cmd/compile: do not Zext bools to 64bits in amd64 CMOV generation rules + 2025-10-27b8468d8c4ecmd/compile: introduce bytesizeToConst to cleanup switches in prove + 2025-10-279e25c2f6decmd/link: internal linking support for windows/arm64 + 2025-10-27ff2ebf69c4internal/runtime/gc/scan: correct size class size check + 2025-10-279a77aa4f08cmd/compile: add position info to sccp debug messages + 2025-10-2777dc138030cmd/compile: teach prove about unsigned rounding-up divide + 2025-10-27a0f33b2887cmd/compile: change !l.nonzero() into l.maybezero() + 2025-10-275453b788fdcmd/compile: optimize Add64carry with unused carries into plain Add64 + 2025-10-272ce5aab79ecmd/compile: remove 68857 ModU flowLimit workaround in prove + 2025-10-27a50de4bda7cmd/compile: remove 68857 min & max flowLimit workaround in prove + 2025-10-2753be78630acmd/compile: use topo-sort in prove to correctly learn facts while walking once + 2025-10-27dec2b4c83druntime: avoid bound check in freebsd binuptime + 2025-10-27916e682d51cmd/internal/obj, cmd/asm: reclassify the offset of memory access operations on loong64 + 2025-10-272835b994fbcmd/go: remove global loader state variable + 2025-10-27139f89226fcmd/go: use local state for telemetry + 2025-10-278239156571cmd/go: use tagged switch + 2025-10-27d741483a1fcmd/go: increase stmt threshold on amd64 + 2025-10-27a6929cf4a7cmd/go: removed unused code in toolchain.Exec + 2025-10-27180c07e2c1go/types, types2: clarify docs for resolveUnderlying + 2025-10-27d8a32f3d4bgo/types, types2: wrap Named.fromRHS into Named.rhs + 2025-10-27b2af92270fgo/types, types2: verify stateMask transitions in debug mode + 2025-10-2792decdcbaanet/url: further speed up escape and unescape + 2025-10-275f4ec3541fruntime: remove unused cgoCheckUsingType function + 2025-10-27189f2c08cctime: rewrite IsZero method to use wall and ext fields + 2025-10-27f619b4a00dcmd/go: reorder parameters so that context is first + 2025-10-27f527994c61sync: update comments for Once.done + 2025-10-265dcaf9a01bruntime: add GOEXPERIMENT=runtimefree + 2025-10-26d7a52f9369cmd/compile: use MOV(D|F) with const for Const(64|32)F on riscv64 + 2025-10-266f04a92be3internal/chacha8rand: provide vector implementation for riscv64 + 2025-10-2654e3adc533cmd/go: use local loader state in test + 2025-10-26ca379b1c56cmd/go: remove loaderstate dependency + 2025-10-2683a44bde64cmd/go: remove unused loader state + 2025-10-267e7cd9de68cmd/go: remove temporary rf cleanup script + 2025-10-2653ad68de4bcmd/compile: allow unaligned load/store on Wasm + 2025-10-2512ec09f434cmd/go: use local state object in work.runBuild and work.runInstall + 2025-10-24643f80a11fruntime: add ppc and s390 to 32 build constraints for gccgo + 2025-10-240afbeb5102runtime: add ppc and s390 to linux 32 bits syscall build constraints for gccgo + 2025-10-247b506d106fcmd/go: use local state object in `generate.runGenerate` + 2025-10-2426a8a21d7fcmd/go: use local state object in `env.runEnv` + 2025-10-24f2dd3d7e31cmd/go: use local state object in `vet.runVet` + 2025-10-24784700439acmd/go: use local state object in pkg `workcmd` + 2025-10-2469673e9be2cmd/go: use local state object in `tool.runTool` + 2025-10-242e12c5db11cmd/go: use local state object in `test.runTest` + 2025-10-24fe345ff2aecmd/go: use local state object in `modget.runGet` + 2025-10-24d312e27e8bcmd/go: use local state object in pkg `modcmd` + 2025-10-24ea9cf26aa1cmd/go: use local state object in `list.runList` + 2025-10-249926e1124ecmd/go: use local state object in `bug.runBug` + 2025-10-242c4fd7b2cdcmd/go: use local state object in `run.runRun` + 2025-10-24ade9f33e1fcmd/go: add loaderstate as field on `mvsReqs` + 2025-10-24ccf4192a31cmd/go: make ImportMissingError work with local state + 2025-10-24f5403f15f0debug/pe: check for zdebug_gdb_scripts section in testDWARF + 2025-10-24a26f860fa4runtime: use 32-bit hash for maps on Wasm + 2025-10-24747fe2efedencoding/json/v2: fix typo in documentation about errors.AsType + 2025-10-2494f47fc03fcmd/link: remove pointless assignment in SetSymAlign + 2025-10-24e6cff69051crypto/x509: move constraint checking after chain building + 2025-10-24f5f69a3de9encoding/json/jsontext: avoid pinning application data in pools + 2025-10-24a6a59f0762encoding/json/v2: use slices.Sort directly + 2025-10-240d3dab9b1dcrypto/x509: simplify candidate chain filtering + 2025-10-2429046398bbcmd/go: refactor injection of modload.LoaderState + 2025-10-24c18fa69e52cmd/go: make ErrNoModRoot work with local state + 2025-10-24296ecc918dcmd/go: add modload.State parameter to AllowedFunc + 2025-10-24c445a61e52cmd/go: add loaderstate as field on `QueryMatchesMainModulesError` + 2025-10-246ac40051d3cmd/go: remove module loader state from ccompile + 2025-10-246a5a452528cmd/go: inject vendor dir into builder struct + 2025-10-23dfac972233crypto/pbkdf2: add missing error return value in example + 2025-10-2347bf8f073eunique: fix inconsistent panic prefix in canonmap cleanup path + 2025-10-2303bd43e8bbgo/types, types2: rename Named.resolve to unpack + 2025-10-239fcdc814b2go/types, types2: rename loaded namedState to lazyLoaded + 2025-10-238401512a9bgo/types, types2: rename complete namedState to hasMethods + 2025-10-23cf826bfcb4go/types, types2: set t.underlying exactly once in resolveUnderlying + 2025-10-23c4e910895bnet/url: speed up escape and unescape + 2025-10-233f6ac3a10fgo/build: use slices.Equal + 2025-10-23839da71f89encoding/pem: properly calculate end indexes + 2025-10-2339ed968832cmd: update golang.org/x/arch for riscv64 disassembler + 2025-10-23ca448191c9all: replace Split in loops with more efficient SplitSeq + 2025-10-23107fcb70deinternal/goroot: replace HasPrefix+TrimPrefix with CutPrefix + 2025-10-238378276d66strconv: optimize int-to-decimal and use consistently + 2025-10-23e5688d0bddcmd/internal/obj/riscv: simplify validation and encoding of raw instructions + 2025-10-2277fc27972adoc/next: improve new(expr) release note + 2025-10-22d94a8c56adruntime: cleanup pagetrace + 2025-10-2202728a2846crypto/internal/fips140test: add entropy SHA2-384 testing + 2025-10-22f92e01c117runtime/cgo: fix cgoCheckArg description + 2025-10-2250586182abruntime: use backoff and ISB instruction to reduce contention in (*lfstack).pop and (*spanSet).pop on arm64 + 2025-10-221ff59f3dd3strconv: clean up powers-of-10 table, tests + 2025-10-227c9fa4d5e9cmd/go: check if build output should overwrite files with renames + 2025-10-22557b4d6e0fcomment: change slice to string in function comment/help + 2025-10-22d09a8c8ef4go/types, types2: simplify locking in Named.resolveUnderlying + 2025-10-225a42af7f6cgo/types, types2: in resolveUnderlying, only compute path when needed + 2025-10-224bdb55b5b8go/types, types2: rename Named.under to Named.resolveUnderlying + 2025-10-2129d43df8abgo/build, cmd/go: use ast.ParseDirective for go:embed + 2025-10-214e695dd634go/ast: add ParseDirective for parsing directive comments + 2025-10-2106e57e60a7go/types, types2: only report version errors if new(expr) is ok otherwise + 2025-10-216c3d0d259fpath/filepath: reword documentation for Rel + 2025-10-2139fd61ddb0go/types, types2: guard Named.underlying with Named.mu + 2025-10-214a0115c886runtime,syscall: implement and use syscalln on darwin + 2025-10-21261c561f5aall: gofmt -w + 2025-10-21c9c78c06efstrconv: embed testdata in test + 2025-10-218f74f9daf4sync: re-enable race even when panicking + 2025-10-218a6c64f4fesyscall: use rawSyscall6 to call ptrace in forkAndExecInChild + 2025-10-214620db72d2runtime: use timer_settime64 on 32-bit Linux + 2025-10-21b31dc77ceaos: support deleting read-only files in RemoveAll on older Windows versions + 2025-10-2146cc532900cmd/compile/internal/ssa: fix typo in comment + 2025-10-212163a58021crypto/internal/fips140/entropy: increase AllocsPerRun iterations + 2025-10-21306eacbc11cmd/go/testdata/script: disable list_empty_importpath test on Windows + 2025-10-21a5a249d6a6all: eliminate unnecessary type conversions + 2025-10-21694182d77bcmd/internal/obj/ppc64: improve large prologue generation + 2025-10-21b0dcb95542cmd/compile: leave the horses alone + 2025-10-219a5a1202f4runtime: clean dead architectures from go:build constraint + 2025-10-218539691d0ccrypto/internal/fips140/entropy: move to crypto/internal/entropy/v1.0.0 + 2025-10-2099cf4d671cruntime: save lasx and lsx registers in loong64 async preemption + 2025-10-2079ae97fe9bruntime: make procyieldAsm no longer loop infinitely if passed 0 + 2025-10-20f838faffe2runtime: wrap procyield assembly and check for 0 + 2025-10-20ee4d2c312druntime/trace: dump test traces on validation failure + 2025-10-207b81a1e107net/url: reduce allocs in Encode + 2025-10-20e425176843cmd/asm: fix typo in comment + 2025-10-20dc9a3e2a65runtime: fix generation skew with trace reentrancy + 2025-10-20df33c17091runtime: add _Gdeadextra status + 2025-10-207503856d40cmd/go: inject loaderstate into matcher function + 2025-10-20d57c3fd743cmd/go: inject State parameter into `work.runInstall` + 2025-10-20e94a5008f6cmd/go: inject State parameter into `work.runBuild` + 2025-10-20d9e6f95450cmd/go: inject State parameter into `workcmd.runSync` + 2025-10-209769a61e64cmd/go: inject State parameter into `modget.runGet` + 2025-10-20f859799ccfcmd/go: inject State parameter into `modcmd.runVerify` + 2025-10-200f820aca29cmd/go: inject State parameter into `modcmd.runVendor` + 2025-10-2092aa3e9e98cmd/go: inject State parameter into `modcmd.runInit` + 2025-10-20e176dff41ccmd/go: inject State parameter into `modcmd.runDownload` + 2025-10-20e7c66a58d5cmd/go: inject State parameter into `toolchain.Select` + 2025-10-204dc3dd9a86cmd/go: add loaderstate to Switcher + 2025-10-20bcf7da1595cmd/go: convert functions to methods + 2025-10-200d3044f965cmd/go: make Reset work with any State instance + 2025-10-20386d81151dcmd/go: make setState work with any State instance + 2025-10-20a420aa221ecmd/go: inject State parameter into `tool.runTool` + 2025-10-20441e7194a4cmd/go: inject State parameter into `test.runTest` + 2025-10-2035e8309be2cmd/go: inject State parameter into `list.runList` + 2025-10-2029a81624f7cmd/go: inject state parameter into `fmtcmd.runFmt` + 2025-10-20f7eaea02fdcmd/go: inject state parameter into `clean.runClean` + 2025-10-2058a8fdb6cfcmd/go: inject State parameter into `bug.runBug` + 2025-10-208d0bef7fferuntime: add linkname documentation and guidance + 2025-10-203e43f48cb6encoding/asn1: use reflect.TypeAssert to improve performance + 2025-10-204ad5585c2cruntime: fix _rt0_ppc64x_lib on aix + 2025-10-17a5f55a441ecmd/fix: add modernize and inline analyzers + 2025-10-1780876f4b42cmd/go/internal/vet: tweak help doc + 2025-10-17b5aefe07e5all: remove unnecessary loop variable copies in tests + 2025-10-175137c473b6go/types, types2: remove references to under function in comments + 2025-10-17dbbb1bfc91all: correct name for comments + 2025-10-170983090171encoding/pem: properly decode strange PEM data + 2025-10-1736863d6194runtime: unify riscv64 library entry point + 2025-10-160c14000f87go/types, types2: remove under(Type) in favor of Type.Underlying() + 2025-10-161099436f1bgo/types, types2: change and enforce lifecycle of Named.fromRHS and Named.underlying fields + 2025-10-1641f5659347go/types, types2: remove superfluous unalias call (minor cleanup) + 2025-10-16e7351c03c8runtime: use DC ZVA instead of its encoding in WORD in arm64 memclr + 2025-10-166cbe0920c4cmd: update to x/tools@7d9453cc + 2025-10-1545eee553e2cmd/internal/obj: move ARM64RegisterExtension from cmd/asm/internal/arch + 2025-10-1527f9a6705cruntime: increase repeat count for alloc test + 2025-10-15b68cebd809net/http/httptest: record failed ResponseWriter writes + 2025-10-15f1fed742ebcmd: fix three printf problems reported by newest vet + 2025-10-150984dcd757cmd/compile: fix an error in comments + 2025-10-1531f82877e8go/types, types2: fix misleading internal comment + 2025-10-156346349f56cmd/compile: replace angle brackets with square + 2025-10-15284379cdfccmd/compile: remove rematerializable values from live set across calls + 2025-10-15519ae514abcmd/compile: eliminate bound check for slices of the same length + 2025-10-15b5a29cca48cmd/distpack: add fix tool to inventory + 2025-10-15bb5eb51715runtime/pprof: fix errors in pprof_test + 2025-10-155c9a26c7f8cmd/compile: use arm64 neon in LoweredMemmove/LoweredMemmoveLoop + 2025-10-1561d1ff61adcmd/compile: use block starting position for phi line number + 2025-10-155b29875c8ecmd/go: inject State parameter into `run.runRun` + 2025-10-155113496805runtime/pprof: skip flaky test TestProfilerStackDepth/heap for now + 2025-10-1536086e85f8cmd/go: create temporary cleanup script + 2025-10-147056c71d32cmd/compile: disable use of new saturating float-to-int conversions + 2025-10-146d5b13793fRevert "cmd/compile: make 386 float-to-int conversions match amd64" + 2025-10-14bb2a14252bRevert "runtime: adjust softfloat corner cases to match amd64/arm64" + 2025-10-143bc9d9fa83Revert "cmd/compile: make wasm match other platforms for FP->int32/64 conversions" + 2025-10-14ee5af46172encoding/json: avoid misleading errors under goexperiment.jsonv2 + 2025-10-1411d3d2f77dcmd/internal/obj/arm64: add support for PAC instructions + 2025-10-144dbf1a5a4ccmd/compile/internal/devirtualize: do not track assignments to non-PAUTO + 2025-10-140ddb5ed465cmd/compile/internal/devirtualize: use FatalfAt instead of Fatalf where possible + 2025-10-140a239bcc99Revert "net/url: disallow raw IPv6 addresses in host" + 2025-10-145a9ef44bc0cmd/compile/internal/devirtualize: fix OCONVNOP assertion + 2025-10-143765758b96go/types, types2: minor cleanup (remove TODO) + 2025-10-14f6b9d56affcrypto/internal/fips140/entropy: fix benign race + 2025-10-1460f6d2f623crypto/internal/fips140/entropy: support SHA-384 sizes for ACVP tests + 2025-10-136fd8e88d07encoding/json/v2: restrict presence of default options + 2025-10-131abc6b0204go/types, types2: permit type cycles through type parameter lists + 2025-10-139fdd6904dastrconv: add tests that Java once mishandled + 2025-10-139b8742f2e7cmd/compile: don't depend on arch-dependent conversions in the compiler + 2025-10-130e64ee1286encoding/json/v2: report EOF for top-level values in UnmarshalDecode + 2025-10-136bcd97d9f4all: replace calls to errors.As with errors.AsType + 2025-10-111cd71689f2crypto/x509: rework fix for CVE-2025-58187 + 2025-10-118aa1efa223cmd/link: in TestFallocate, only check number of blocks on Darwin + 2025-10-10b497a29d25encoding/json: fix regression in quoted numbers under goexperiment.jsonv2 + 2025-10-1048bb7a6114cmd/compile: repair bisection behavior for float-to-unsigned conversion + 2025-10-10e8a53538b4runtime: fail TestGoroutineLeakProfile on data race + 2025-10-10e3be2d1b2bnet/url: disallow raw IPv6 addresses in host + 2025-10-10aced4c79a2net/http: strip request body headers on POST to GET redirects + 2025-10-10584a89fe74all: omit unnecessary reassignment + 2025-10-1069e8279632net/http: set cookie host to Request.Host when available + 2025-10-106f4c63ba63cmd/go: unify "go fix" and "go vet" + 2025-10-10955a5a0dc5runtime: support arm64 Neon in async preemption + 2025-10-105368e77429net/http: run TestRequestWriteTransport with fake time to avoid flakes + 2025-10-09c53cb642deinternal/buildcfg: enable greenteagc experiment for loong64 + 2025-10-09954fdcc51acmd/compile: declare no output register for loong64 LoweredAtomic{And,Or}32 ops + 2025-10-0919a30ea3f2cmd/compile: call generated size-specialized malloc functions directly + 2025-10-0980f3bb5516reflect: remove timeout in TestChanOfGC + 2025-10-099db7e30bb4net/url: allow IP-literals with IPv4-mapped IPv6 addresses + 2025-10-098d810286b3cmd/compile: make wasm match other platforms for FP->int32/64 conversions + 2025-10-09b9f3accdcfruntime: adjust softfloat corner cases to match amd64/arm64 + 2025-10-0978d75b3799cmd/compile: make 386 float-to-int conversions match amd64 + 2025-10-090e466a8d1dcmd/compile: modify float-to-[u]int so that amd64 and arm64 match + 2025-10-084837fbe414net/http/httptest: check whether response bodies are allowed + 2025-10-08ee163197a8path/filepath: return cleaned path from Rel + 2025-10-08de9da0de30cmd/compile/internal/devirtualize: improve concrete type analysis + 2025-10-08ae094a1397crypto/internal/fips140test: make entropy file pair names match + 2025-10-08941e5917c1runtime: cleanup comments from asm_ppc64x.s improvements + 2025-10-08d945600d06cmd/gofmt: change -d to exit 1 if diffs exist + 2025-10-08d4830c6130cmd/internal/obj: fix Link.Diag printf errors + 2025-10-08e1ca1de123net/http: format pprof.go + 2025-10-08e5d004c7a8net/http: update HTTP/2 documentation to reference new config features + 2025-10-0897fd6bdecccmd/compile: fuse NaN checks with other comparisons + 2025-10-0778b43037dccmd/go: refactor usage of `workFilePath` + 2025-10-07bb1ca7ae81cmd/go, testing: add TB.ArtifactDir and -artifacts flag + 2025-10-071623927730cmd/go: refactor usage of `requirements` + 2025-10-07a1661e776fRevert "crypto/internal/fips140/subtle: add assembly implementation of xorBytes for mips64x" + 2025-10-07cb81270113Revert "crypto/internal/fips140/subtle: add assembly implementation of xorBytes for mipsx" + 2025-10-07f2d0d05d28cmd/go: refactor usage of `MainModules` + 2025-10-07f7a68d3804archive/tar: set a limit on the size of GNU sparse file 1.0 regions + 2025-10-07463165699dnet/mail: avoid quadratic behavior in mail address parsing + 2025-10-075ede095649net/textproto: avoid quadratic complexity in Reader.ReadResponse + 2025-10-075ce8cd16f3encoding/pem: make Decode complexity linear + 2025-10-07f6f4e8b3efnet/url: enforce stricter parsing of bracketed IPv6 hostnames + 2025-10-077dd54e1fd7runtime: make work.spanSPMCs.all doubly-linked + 2025-10-073ee761739bruntime: free spanQueue on P destroy + 2025-10-078709a41d5eencoding/asn1: prevent memory exhaustion when parsing using internal/saferio + 2025-10-079b9d02c5a0net/http: add httpcookiemaxnum GODEBUG option to limit number of cookies parsed + 2025-10-073fc4c79fdbcrypto/x509: improve domain name verification + 2025-10-076e4007e8cfcrypto/x509: mitigate DoS vector when intermediate certificate contains DSA public key + 2025-10-076f7926589dcmd/go: refactor usage of `modRoots` + 2025-10-0711d5484190runtime: fix self-deadlock on sbrk platforms + 2025-10-072e52060084cmd/go: refactor usage of `RootMode` + 2025-10-07f86ddb54b5cmd/go: refactor usage of `ForceUseModules` + 2025-10-07c938051dd0Revert "cmd/compile: redo arm64 LR/FP save and restore" + 2025-10-076469954203runtime: assert p.destroy runs with GC not running + 2025-10-064c0fd3a2b4internal/goexperiment: remove the synctest GOEXPERIMENT + 2025-10-06c1e6e49d5dfmt: reduce Errorf("x") allocations to match errors.New("x") + 2025-10-067fbf54bfebinternal/buildcfg: enable greenteagc experiment by default + 2025-10-067bfeb43509cmd/go: refactor usage of `initialized` + 2025-10-061d62e92567test/codegen: make sure assignment results are used. + 2025-10-064fca79833fruntime: delete redundant code in the page allocator + 2025-10-06719dfcf8a8cmd/compile: redo arm64 LR/FP save and restore + 2025-10-06f3312124c2runtime: remove batching from spanSPMC free + 2025-10-0624416458c2cmd/go: export type State + 2025-10-06c2fb15164btesting/synctest: remove Run + 2025-10-06ac2ec82172runtime: bump thread count slack for TestReadMetricsSched + 2025-10-06e74b224b7ccrypto/tls: streamline BoGo testing w/ -bogo-local-dir + 2025-10-063a05e7b032spec: close tag + 2025-10-032a71af11fcnet/url: improve URL docs + 2025-10-03ee5369b003cmd/link: add LIBRARY statement only with -buildmode=cshared + 2025-10-031bca4c1673cmd/compile: improve slicemask removal + 2025-10-0338b26f29f1cmd/compile: remove stores to unread parameters + 2025-10-03003b5ce1bccmd/compile: fix SIMD const rematerialization condition + 2025-10-03d91148c7a8cmd/compile: enhance prove to infer bounds in slice len/cap calculations + 2025-10-0320c9377e47cmd/compile: enhance the chunked indexing case to include reslicing + 2025-10-03ad3db2562ecmd/compile: handle rematerialized op for incompatible reg constraint + 2025-10-0318cd4a1fc7cmd/compile: use the right type for spill slot + 2025-10-031caa95acfacmd/compile: enhance prove to deal with double-offset IsInBounds checks + 2025-10-03ec70d19023cmd/compile: rewrite to elide Slicemask from len==c>0 slicing + 2025-10-0310e7968849cmd/compile: accounts rematerialize ops's output reginfo + 2025-10-03ab043953cbcmd/compile: minor tweak for race detector + 2025-10-03ebb72bef44cmd/compile: don't treat devel compiler as a released compiler + 2025-10-03c54dc1418bruntime: support valgrind (but not asan) in specialized malloc functions + 2025-10-03a7917eed70internal/buildcfg: enable specializedmalloc experiment + 2025-10-03630799c6c9crypto/tls: add flag to render HTML BoGo report Change-Id: I6bf904c523a77ee7d3dea9c8ae72292f8a5f2ba5
1282 lines
32 KiB
Go
1282 lines
32 KiB
Go
// Copyright 2020 The Go Authors. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style
|
|
// license that can be found in the LICENSE file.
|
|
|
|
package ir
|
|
|
|
import (
|
|
"bytes"
|
|
"cmd/compile/internal/base"
|
|
"cmd/compile/internal/types"
|
|
"cmd/internal/obj"
|
|
"cmd/internal/src"
|
|
"fmt"
|
|
"go/constant"
|
|
"go/token"
|
|
)
|
|
|
|
// An Expr is a Node that can appear as an expression.
|
|
type Expr interface {
|
|
Node
|
|
isExpr()
|
|
}
|
|
|
|
// A miniExpr is a miniNode with extra fields common to expressions.
|
|
// TODO(rsc): Once we are sure about the contents, compact the bools
|
|
// into a bit field and leave extra bits available for implementations
|
|
// embedding miniExpr. Right now there are ~24 unused bits sitting here.
|
|
type miniExpr struct {
|
|
miniNode
|
|
flags bitset8
|
|
typ *types.Type
|
|
init Nodes // TODO(rsc): Don't require every Node to have an init
|
|
}
|
|
|
|
const (
|
|
miniExprNonNil = 1 << iota
|
|
miniExprTransient
|
|
miniExprBounded
|
|
miniExprImplicit // for use by implementations; not supported by every Expr
|
|
miniExprCheckPtr
|
|
)
|
|
|
|
func (*miniExpr) isExpr() {}
|
|
|
|
func (n *miniExpr) Type() *types.Type { return n.typ }
|
|
func (n *miniExpr) SetType(x *types.Type) { n.typ = x }
|
|
func (n *miniExpr) NonNil() bool { return n.flags&miniExprNonNil != 0 }
|
|
func (n *miniExpr) MarkNonNil() { n.flags |= miniExprNonNil }
|
|
func (n *miniExpr) Transient() bool { return n.flags&miniExprTransient != 0 }
|
|
func (n *miniExpr) SetTransient(b bool) { n.flags.set(miniExprTransient, b) }
|
|
func (n *miniExpr) Bounded() bool { return n.flags&miniExprBounded != 0 }
|
|
func (n *miniExpr) SetBounded(b bool) { n.flags.set(miniExprBounded, b) }
|
|
func (n *miniExpr) Init() Nodes { return n.init }
|
|
func (n *miniExpr) PtrInit() *Nodes { return &n.init }
|
|
func (n *miniExpr) SetInit(x Nodes) { n.init = x }
|
|
|
|
// An AddStringExpr is a string concatenation List[0] + List[1] + ... + List[len(List)-1].
|
|
type AddStringExpr struct {
|
|
miniExpr
|
|
List Nodes
|
|
Prealloc *Name
|
|
}
|
|
|
|
func NewAddStringExpr(pos src.XPos, list []Node) *AddStringExpr {
|
|
n := &AddStringExpr{}
|
|
n.pos = pos
|
|
n.op = OADDSTR
|
|
n.List = list
|
|
return n
|
|
}
|
|
|
|
// An AddrExpr is an address-of expression &X.
|
|
// It may end up being a normal address-of or an allocation of a composite literal.
|
|
type AddrExpr struct {
|
|
miniExpr
|
|
X Node
|
|
Prealloc *Name // preallocated storage if any
|
|
}
|
|
|
|
func NewAddrExpr(pos src.XPos, x Node) *AddrExpr {
|
|
if x == nil || x.Typecheck() != 1 {
|
|
base.FatalfAt(pos, "missed typecheck: %L", x)
|
|
}
|
|
n := &AddrExpr{X: x}
|
|
n.pos = pos
|
|
|
|
switch x.Op() {
|
|
case OARRAYLIT, OMAPLIT, OSLICELIT, OSTRUCTLIT:
|
|
n.op = OPTRLIT
|
|
|
|
default:
|
|
n.op = OADDR
|
|
if r, ok := OuterValue(x).(*Name); ok && r.Op() == ONAME {
|
|
r.SetAddrtaken(true)
|
|
|
|
// If r is a closure variable, we need to mark its canonical
|
|
// variable as addrtaken too, so that closure conversion
|
|
// captures it by reference.
|
|
//
|
|
// Exception: if we've already marked the variable as
|
|
// capture-by-value, then that means this variable isn't
|
|
// logically modified, and we must be taking its address to pass
|
|
// to a runtime function that won't mutate it. In that case, we
|
|
// only need to make sure our own copy is addressable.
|
|
if r.IsClosureVar() && !r.Byval() {
|
|
r.Canonical().SetAddrtaken(true)
|
|
}
|
|
}
|
|
}
|
|
|
|
n.SetType(types.NewPtr(x.Type()))
|
|
n.SetTypecheck(1)
|
|
|
|
return n
|
|
}
|
|
|
|
func (n *AddrExpr) Implicit() bool { return n.flags&miniExprImplicit != 0 }
|
|
func (n *AddrExpr) SetImplicit(b bool) { n.flags.set(miniExprImplicit, b) }
|
|
|
|
func (n *AddrExpr) SetOp(op Op) {
|
|
switch op {
|
|
default:
|
|
panic(n.no("SetOp " + op.String()))
|
|
case OADDR, OPTRLIT:
|
|
n.op = op
|
|
}
|
|
}
|
|
|
|
// A BasicLit is a literal of basic type.
|
|
type BasicLit struct {
|
|
miniExpr
|
|
val constant.Value
|
|
}
|
|
|
|
// NewBasicLit returns an OLITERAL representing val with the given type.
|
|
func NewBasicLit(pos src.XPos, typ *types.Type, val constant.Value) Node {
|
|
AssertValidTypeForConst(typ, val)
|
|
|
|
n := &BasicLit{val: val}
|
|
n.op = OLITERAL
|
|
n.pos = pos
|
|
n.SetType(typ)
|
|
n.SetTypecheck(1)
|
|
return n
|
|
}
|
|
|
|
func (n *BasicLit) Val() constant.Value { return n.val }
|
|
func (n *BasicLit) SetVal(val constant.Value) { n.val = val }
|
|
|
|
// NewConstExpr returns an OLITERAL representing val, copying the
|
|
// position and type from orig.
|
|
func NewConstExpr(val constant.Value, orig Node) Node {
|
|
return NewBasicLit(orig.Pos(), orig.Type(), val)
|
|
}
|
|
|
|
// A BinaryExpr is a binary expression X Op Y,
|
|
// or Op(X, Y) for builtin functions that do not become calls.
|
|
type BinaryExpr struct {
|
|
miniExpr
|
|
X Node
|
|
Y Node
|
|
RType Node `mknode:"-"` // see reflectdata/helpers.go
|
|
}
|
|
|
|
func NewBinaryExpr(pos src.XPos, op Op, x, y Node) *BinaryExpr {
|
|
n := &BinaryExpr{X: x, Y: y}
|
|
n.pos = pos
|
|
n.SetOp(op)
|
|
return n
|
|
}
|
|
|
|
func (n *BinaryExpr) SetOp(op Op) {
|
|
switch op {
|
|
default:
|
|
panic(n.no("SetOp " + op.String()))
|
|
case OADD, OADDSTR, OAND, OANDNOT, ODIV, OEQ, OGE, OGT, OLE,
|
|
OLSH, OLT, OMOD, OMUL, ONE, OOR, ORSH, OSUB, OXOR,
|
|
OCOPY, OCOMPLEX, OUNSAFEADD, OUNSAFESLICE, OUNSAFESTRING,
|
|
OMAKEFACE:
|
|
n.op = op
|
|
}
|
|
}
|
|
|
|
// A CallExpr is a function call Fun(Args).
|
|
type CallExpr struct {
|
|
miniExpr
|
|
Fun Node
|
|
Args Nodes
|
|
DeferAt Node
|
|
RType Node `mknode:"-"` // see reflectdata/helpers.go
|
|
KeepAlive []*Name // vars to be kept alive until call returns
|
|
IsDDD bool
|
|
GoDefer bool // whether this call is part of a go or defer statement
|
|
NoInline bool // whether this call must not be inlined
|
|
}
|
|
|
|
func NewCallExpr(pos src.XPos, op Op, fun Node, args []Node) *CallExpr {
|
|
n := &CallExpr{Fun: fun}
|
|
n.pos = pos
|
|
n.SetOp(op)
|
|
n.Args = args
|
|
return n
|
|
}
|
|
|
|
func (*CallExpr) isStmt() {}
|
|
|
|
func (n *CallExpr) SetOp(op Op) {
|
|
switch op {
|
|
default:
|
|
panic(n.no("SetOp " + op.String()))
|
|
case OAPPEND,
|
|
OCALL, OCALLFUNC, OCALLINTER, OCALLMETH,
|
|
ODELETE,
|
|
OGETG, OGETCALLERSP,
|
|
OMAKE, OMAX, OMIN, OPRINT, OPRINTLN,
|
|
ORECOVER:
|
|
n.op = op
|
|
}
|
|
}
|
|
|
|
// A ClosureExpr is a function literal expression.
|
|
type ClosureExpr struct {
|
|
miniExpr
|
|
Func *Func `mknode:"-"`
|
|
Prealloc *Name
|
|
IsGoWrap bool // whether this is wrapper closure of a go statement
|
|
}
|
|
|
|
// A CompLitExpr is a composite literal Type{Vals}.
|
|
// Before type-checking, the type is Ntype.
|
|
type CompLitExpr struct {
|
|
miniExpr
|
|
List Nodes // initialized values
|
|
RType Node `mknode:"-"` // *runtime._type for OMAPLIT map types
|
|
Prealloc *Name
|
|
// For OSLICELIT, Len is the backing array length.
|
|
// For OMAPLIT, Len is the number of entries that we've removed from List and
|
|
// generated explicit mapassign calls for. This is used to inform the map alloc hint.
|
|
Len int64
|
|
}
|
|
|
|
func NewCompLitExpr(pos src.XPos, op Op, typ *types.Type, list []Node) *CompLitExpr {
|
|
n := &CompLitExpr{List: list}
|
|
n.pos = pos
|
|
n.SetOp(op)
|
|
if typ != nil {
|
|
n.SetType(typ)
|
|
}
|
|
return n
|
|
}
|
|
|
|
func (n *CompLitExpr) Implicit() bool { return n.flags&miniExprImplicit != 0 }
|
|
func (n *CompLitExpr) SetImplicit(b bool) { n.flags.set(miniExprImplicit, b) }
|
|
|
|
func (n *CompLitExpr) SetOp(op Op) {
|
|
switch op {
|
|
default:
|
|
panic(n.no("SetOp " + op.String()))
|
|
case OARRAYLIT, OCOMPLIT, OMAPLIT, OSTRUCTLIT, OSLICELIT:
|
|
n.op = op
|
|
}
|
|
}
|
|
|
|
// A ConvExpr is a conversion Type(X).
|
|
// It may end up being a value or a type.
|
|
type ConvExpr struct {
|
|
miniExpr
|
|
X Node
|
|
|
|
// For implementing OCONVIFACE expressions.
|
|
//
|
|
// TypeWord is an expression yielding a *runtime._type or
|
|
// *runtime.itab value to go in the type word of the iface/eface
|
|
// result. See reflectdata.ConvIfaceTypeWord for further details.
|
|
//
|
|
// SrcRType is an expression yielding a *runtime._type value for X,
|
|
// if it's not pointer-shaped and needs to be heap allocated.
|
|
TypeWord Node `mknode:"-"`
|
|
SrcRType Node `mknode:"-"`
|
|
|
|
// For -d=checkptr instrumentation of conversions from
|
|
// unsafe.Pointer to *Elem or *[Len]Elem.
|
|
//
|
|
// TODO(mdempsky): We only ever need one of these, but currently we
|
|
// don't decide which one until walk. Longer term, it probably makes
|
|
// sense to have a dedicated IR op for `(*[Len]Elem)(ptr)[:n:m]`
|
|
// expressions.
|
|
ElemRType Node `mknode:"-"`
|
|
ElemElemRType Node `mknode:"-"`
|
|
}
|
|
|
|
func NewConvExpr(pos src.XPos, op Op, typ *types.Type, x Node) *ConvExpr {
|
|
n := &ConvExpr{X: x}
|
|
n.pos = pos
|
|
n.typ = typ
|
|
n.SetOp(op)
|
|
return n
|
|
}
|
|
|
|
func (n *ConvExpr) Implicit() bool { return n.flags&miniExprImplicit != 0 }
|
|
func (n *ConvExpr) SetImplicit(b bool) { n.flags.set(miniExprImplicit, b) }
|
|
func (n *ConvExpr) CheckPtr() bool { return n.flags&miniExprCheckPtr != 0 }
|
|
func (n *ConvExpr) SetCheckPtr(b bool) { n.flags.set(miniExprCheckPtr, b) }
|
|
|
|
func (n *ConvExpr) SetOp(op Op) {
|
|
switch op {
|
|
default:
|
|
panic(n.no("SetOp " + op.String()))
|
|
case OCONV, OCONVIFACE, OCONVNOP, OBYTES2STR, OBYTES2STRTMP, ORUNES2STR, OSTR2BYTES, OSTR2BYTESTMP, OSTR2RUNES, ORUNESTR, OSLICE2ARR, OSLICE2ARRPTR:
|
|
n.op = op
|
|
}
|
|
}
|
|
|
|
// An IndexExpr is an index expression X[Index].
|
|
type IndexExpr struct {
|
|
miniExpr
|
|
X Node
|
|
Index Node
|
|
RType Node `mknode:"-"` // see reflectdata/helpers.go
|
|
Assigned bool
|
|
}
|
|
|
|
func NewIndexExpr(pos src.XPos, x, index Node) *IndexExpr {
|
|
n := &IndexExpr{X: x, Index: index}
|
|
n.pos = pos
|
|
n.op = OINDEX
|
|
return n
|
|
}
|
|
|
|
func (n *IndexExpr) SetOp(op Op) {
|
|
switch op {
|
|
default:
|
|
panic(n.no("SetOp " + op.String()))
|
|
case OINDEX, OINDEXMAP:
|
|
n.op = op
|
|
}
|
|
}
|
|
|
|
// A KeyExpr is a Key: Value composite literal key.
|
|
type KeyExpr struct {
|
|
miniExpr
|
|
Key Node
|
|
Value Node
|
|
}
|
|
|
|
func NewKeyExpr(pos src.XPos, key, value Node) *KeyExpr {
|
|
n := &KeyExpr{Key: key, Value: value}
|
|
n.pos = pos
|
|
n.op = OKEY
|
|
return n
|
|
}
|
|
|
|
// A StructKeyExpr is a Field: Value composite literal key.
|
|
type StructKeyExpr struct {
|
|
miniExpr
|
|
Field *types.Field
|
|
Value Node
|
|
}
|
|
|
|
func NewStructKeyExpr(pos src.XPos, field *types.Field, value Node) *StructKeyExpr {
|
|
n := &StructKeyExpr{Field: field, Value: value}
|
|
n.pos = pos
|
|
n.op = OSTRUCTKEY
|
|
return n
|
|
}
|
|
|
|
func (n *StructKeyExpr) Sym() *types.Sym { return n.Field.Sym }
|
|
|
|
// An InlinedCallExpr is an inlined function call.
|
|
type InlinedCallExpr struct {
|
|
miniExpr
|
|
Body Nodes
|
|
ReturnVars Nodes // must be side-effect free
|
|
}
|
|
|
|
func NewInlinedCallExpr(pos src.XPos, body, retvars []Node) *InlinedCallExpr {
|
|
n := &InlinedCallExpr{}
|
|
n.pos = pos
|
|
n.op = OINLCALL
|
|
n.Body = body
|
|
n.ReturnVars = retvars
|
|
return n
|
|
}
|
|
|
|
func (n *InlinedCallExpr) SingleResult() Node {
|
|
if have := len(n.ReturnVars); have != 1 {
|
|
base.FatalfAt(n.Pos(), "inlined call has %v results, expected 1", have)
|
|
}
|
|
if !n.Type().HasShape() && n.ReturnVars[0].Type().HasShape() {
|
|
// If the type of the call is not a shape, but the type of the return value
|
|
// is a shape, we need to do an implicit conversion, so the real type
|
|
// of n is maintained.
|
|
r := NewConvExpr(n.Pos(), OCONVNOP, n.Type(), n.ReturnVars[0])
|
|
r.SetTypecheck(1)
|
|
return r
|
|
}
|
|
return n.ReturnVars[0]
|
|
}
|
|
|
|
// A LogicalExpr is an expression X Op Y where Op is && or ||.
|
|
// It is separate from BinaryExpr to make room for statements
|
|
// that must be executed before Y but after X.
|
|
type LogicalExpr struct {
|
|
miniExpr
|
|
X Node
|
|
Y Node
|
|
}
|
|
|
|
func NewLogicalExpr(pos src.XPos, op Op, x, y Node) *LogicalExpr {
|
|
n := &LogicalExpr{X: x, Y: y}
|
|
n.pos = pos
|
|
n.SetOp(op)
|
|
return n
|
|
}
|
|
|
|
func (n *LogicalExpr) SetOp(op Op) {
|
|
switch op {
|
|
default:
|
|
panic(n.no("SetOp " + op.String()))
|
|
case OANDAND, OOROR:
|
|
n.op = op
|
|
}
|
|
}
|
|
|
|
// A MakeExpr is a make expression: make(Type[, Len[, Cap]]).
|
|
// Op is OMAKECHAN, OMAKEMAP, OMAKESLICE, or OMAKESLICECOPY,
|
|
// but *not* OMAKE (that's a pre-typechecking CallExpr).
|
|
type MakeExpr struct {
|
|
miniExpr
|
|
RType Node `mknode:"-"` // see reflectdata/helpers.go
|
|
Len Node
|
|
Cap Node
|
|
}
|
|
|
|
func NewMakeExpr(pos src.XPos, op Op, len, cap Node) *MakeExpr {
|
|
n := &MakeExpr{Len: len, Cap: cap}
|
|
n.pos = pos
|
|
n.SetOp(op)
|
|
return n
|
|
}
|
|
|
|
func (n *MakeExpr) SetOp(op Op) {
|
|
switch op {
|
|
default:
|
|
panic(n.no("SetOp " + op.String()))
|
|
case OMAKECHAN, OMAKEMAP, OMAKESLICE, OMAKESLICECOPY:
|
|
n.op = op
|
|
}
|
|
}
|
|
|
|
// A NilExpr represents the predefined untyped constant nil.
|
|
type NilExpr struct {
|
|
miniExpr
|
|
}
|
|
|
|
func NewNilExpr(pos src.XPos, typ *types.Type) *NilExpr {
|
|
if typ == nil {
|
|
base.FatalfAt(pos, "missing type")
|
|
}
|
|
n := &NilExpr{}
|
|
n.pos = pos
|
|
n.op = ONIL
|
|
n.SetType(typ)
|
|
n.SetTypecheck(1)
|
|
return n
|
|
}
|
|
|
|
// A ParenExpr is a parenthesized expression (X).
|
|
// It may end up being a value or a type.
|
|
type ParenExpr struct {
|
|
miniExpr
|
|
X Node
|
|
}
|
|
|
|
func NewParenExpr(pos src.XPos, x Node) *ParenExpr {
|
|
n := &ParenExpr{X: x}
|
|
n.op = OPAREN
|
|
n.pos = pos
|
|
return n
|
|
}
|
|
|
|
func (n *ParenExpr) Implicit() bool { return n.flags&miniExprImplicit != 0 }
|
|
func (n *ParenExpr) SetImplicit(b bool) { n.flags.set(miniExprImplicit, b) }
|
|
|
|
// A ResultExpr represents a direct access to a result.
|
|
type ResultExpr struct {
|
|
miniExpr
|
|
Index int64 // index of the result expr.
|
|
}
|
|
|
|
func NewResultExpr(pos src.XPos, typ *types.Type, index int64) *ResultExpr {
|
|
n := &ResultExpr{Index: index}
|
|
n.pos = pos
|
|
n.op = ORESULT
|
|
n.typ = typ
|
|
return n
|
|
}
|
|
|
|
// A LinksymOffsetExpr refers to an offset within a global variable.
|
|
// It is like a SelectorExpr but without the field name.
|
|
type LinksymOffsetExpr struct {
|
|
miniExpr
|
|
Linksym *obj.LSym
|
|
Offset_ int64
|
|
}
|
|
|
|
func NewLinksymOffsetExpr(pos src.XPos, lsym *obj.LSym, offset int64, typ *types.Type) *LinksymOffsetExpr {
|
|
if typ == nil {
|
|
base.FatalfAt(pos, "nil type")
|
|
}
|
|
n := &LinksymOffsetExpr{Linksym: lsym, Offset_: offset}
|
|
n.typ = typ
|
|
n.op = OLINKSYMOFFSET
|
|
n.SetTypecheck(1)
|
|
return n
|
|
}
|
|
|
|
// NewLinksymExpr is NewLinksymOffsetExpr, but with offset fixed at 0.
|
|
func NewLinksymExpr(pos src.XPos, lsym *obj.LSym, typ *types.Type) *LinksymOffsetExpr {
|
|
return NewLinksymOffsetExpr(pos, lsym, 0, typ)
|
|
}
|
|
|
|
// NewNameOffsetExpr is NewLinksymOffsetExpr, but taking a *Name
|
|
// representing a global variable instead of an *obj.LSym directly.
|
|
func NewNameOffsetExpr(pos src.XPos, name *Name, offset int64, typ *types.Type) *LinksymOffsetExpr {
|
|
if name == nil || IsBlank(name) || !(name.Op() == ONAME && name.Class == PEXTERN) {
|
|
base.FatalfAt(pos, "cannot take offset of nil, blank name or non-global variable: %v", name)
|
|
}
|
|
return NewLinksymOffsetExpr(pos, name.Linksym(), offset, typ)
|
|
}
|
|
|
|
// A SelectorExpr is a selector expression X.Sel.
|
|
type SelectorExpr struct {
|
|
miniExpr
|
|
X Node
|
|
// Sel is the name of the field or method being selected, without (in the
|
|
// case of methods) any preceding type specifier. If the field/method is
|
|
// exported, than the Sym uses the local package regardless of the package
|
|
// of the containing type.
|
|
Sel *types.Sym
|
|
// The actual selected field - may not be filled in until typechecking.
|
|
Selection *types.Field
|
|
Prealloc *Name // preallocated storage for OMETHVALUE, if any
|
|
}
|
|
|
|
func NewSelectorExpr(pos src.XPos, op Op, x Node, sel *types.Sym) *SelectorExpr {
|
|
n := &SelectorExpr{X: x, Sel: sel}
|
|
n.pos = pos
|
|
n.SetOp(op)
|
|
return n
|
|
}
|
|
|
|
func (n *SelectorExpr) SetOp(op Op) {
|
|
switch op {
|
|
default:
|
|
panic(n.no("SetOp " + op.String()))
|
|
case OXDOT, ODOT, ODOTPTR, ODOTMETH, ODOTINTER, OMETHVALUE, OMETHEXPR:
|
|
n.op = op
|
|
}
|
|
}
|
|
|
|
func (n *SelectorExpr) Sym() *types.Sym { return n.Sel }
|
|
func (n *SelectorExpr) Implicit() bool { return n.flags&miniExprImplicit != 0 }
|
|
func (n *SelectorExpr) SetImplicit(b bool) { n.flags.set(miniExprImplicit, b) }
|
|
func (n *SelectorExpr) Offset() int64 { return n.Selection.Offset }
|
|
|
|
func (n *SelectorExpr) FuncName() *Name {
|
|
if n.Op() != OMETHEXPR {
|
|
panic(n.no("FuncName"))
|
|
}
|
|
fn := NewNameAt(n.Selection.Pos, MethodSym(n.X.Type(), n.Sel), n.Type())
|
|
fn.Class = PFUNC
|
|
if n.Selection.Nname != nil {
|
|
// TODO(austin): Nname is nil for interface method
|
|
// expressions (I.M), so we can't attach a Func to
|
|
// those here.
|
|
fn.Func = n.Selection.Nname.(*Name).Func
|
|
}
|
|
return fn
|
|
}
|
|
|
|
// A SliceExpr is a slice expression X[Low:High] or X[Low:High:Max].
|
|
type SliceExpr struct {
|
|
miniExpr
|
|
X Node
|
|
Low Node
|
|
High Node
|
|
Max Node
|
|
}
|
|
|
|
func NewSliceExpr(pos src.XPos, op Op, x, low, high, max Node) *SliceExpr {
|
|
n := &SliceExpr{X: x, Low: low, High: high, Max: max}
|
|
n.pos = pos
|
|
n.op = op
|
|
return n
|
|
}
|
|
|
|
func (n *SliceExpr) SetOp(op Op) {
|
|
switch op {
|
|
default:
|
|
panic(n.no("SetOp " + op.String()))
|
|
case OSLICE, OSLICEARR, OSLICESTR, OSLICE3, OSLICE3ARR:
|
|
n.op = op
|
|
}
|
|
}
|
|
|
|
// IsSlice3 reports whether o is a slice3 op (OSLICE3, OSLICE3ARR).
|
|
// o must be a slicing op.
|
|
func (o Op) IsSlice3() bool {
|
|
switch o {
|
|
case OSLICE, OSLICEARR, OSLICESTR:
|
|
return false
|
|
case OSLICE3, OSLICE3ARR:
|
|
return true
|
|
}
|
|
base.Fatalf("IsSlice3 op %v", o)
|
|
return false
|
|
}
|
|
|
|
// A SliceHeaderExpr constructs a slice header from its parts.
|
|
type SliceHeaderExpr struct {
|
|
miniExpr
|
|
Ptr Node
|
|
Len Node
|
|
Cap Node
|
|
}
|
|
|
|
func NewSliceHeaderExpr(pos src.XPos, typ *types.Type, ptr, len, cap Node) *SliceHeaderExpr {
|
|
n := &SliceHeaderExpr{Ptr: ptr, Len: len, Cap: cap}
|
|
n.pos = pos
|
|
n.op = OSLICEHEADER
|
|
n.typ = typ
|
|
return n
|
|
}
|
|
|
|
// A StringHeaderExpr expression constructs a string header from its parts.
|
|
type StringHeaderExpr struct {
|
|
miniExpr
|
|
Ptr Node
|
|
Len Node
|
|
}
|
|
|
|
func NewStringHeaderExpr(pos src.XPos, ptr, len Node) *StringHeaderExpr {
|
|
n := &StringHeaderExpr{Ptr: ptr, Len: len}
|
|
n.pos = pos
|
|
n.op = OSTRINGHEADER
|
|
n.typ = types.Types[types.TSTRING]
|
|
return n
|
|
}
|
|
|
|
// A StarExpr is a dereference expression *X.
|
|
// It may end up being a value or a type.
|
|
type StarExpr struct {
|
|
miniExpr
|
|
X Node
|
|
}
|
|
|
|
func NewStarExpr(pos src.XPos, x Node) *StarExpr {
|
|
n := &StarExpr{X: x}
|
|
n.op = ODEREF
|
|
n.pos = pos
|
|
return n
|
|
}
|
|
|
|
func (n *StarExpr) Implicit() bool { return n.flags&miniExprImplicit != 0 }
|
|
func (n *StarExpr) SetImplicit(b bool) { n.flags.set(miniExprImplicit, b) }
|
|
|
|
// A TypeAssertExpr is a selector expression X.(Type).
|
|
// Before type-checking, the type is Ntype.
|
|
type TypeAssertExpr struct {
|
|
miniExpr
|
|
X Node
|
|
|
|
// Runtime type information provided by walkDotType for
|
|
// assertions from non-empty interface to concrete type.
|
|
ITab Node `mknode:"-"` // *runtime.itab for Type implementing X's type
|
|
|
|
// An internal/abi.TypeAssert descriptor to pass to the runtime.
|
|
Descriptor *obj.LSym
|
|
|
|
// When set to true, if this assert would panic, then use a nil pointer panic
|
|
// instead of an interface conversion panic.
|
|
// It must not be set for type asserts using the commaok form.
|
|
UseNilPanic bool
|
|
}
|
|
|
|
func NewTypeAssertExpr(pos src.XPos, x Node, typ *types.Type) *TypeAssertExpr {
|
|
n := &TypeAssertExpr{X: x}
|
|
n.pos = pos
|
|
n.op = ODOTTYPE
|
|
if typ != nil {
|
|
n.SetType(typ)
|
|
}
|
|
return n
|
|
}
|
|
|
|
func (n *TypeAssertExpr) SetOp(op Op) {
|
|
switch op {
|
|
default:
|
|
panic(n.no("SetOp " + op.String()))
|
|
case ODOTTYPE, ODOTTYPE2:
|
|
n.op = op
|
|
}
|
|
}
|
|
|
|
// A DynamicTypeAssertExpr asserts that X is of dynamic type RType.
|
|
type DynamicTypeAssertExpr struct {
|
|
miniExpr
|
|
X Node
|
|
|
|
// SrcRType is an expression that yields a *runtime._type value
|
|
// representing X's type. It's used in failed assertion panic
|
|
// messages.
|
|
SrcRType Node
|
|
|
|
// RType is an expression that yields a *runtime._type value
|
|
// representing the asserted type.
|
|
//
|
|
// BUG(mdempsky): If ITab is non-nil, RType may be nil.
|
|
RType Node
|
|
|
|
// ITab is an expression that yields a *runtime.itab value
|
|
// representing the asserted type within the assertee expression's
|
|
// original interface type.
|
|
//
|
|
// ITab is only used for assertions from non-empty interface type to
|
|
// a concrete (i.e., non-interface) type. For all other assertions,
|
|
// ITab is nil.
|
|
ITab Node
|
|
}
|
|
|
|
func NewDynamicTypeAssertExpr(pos src.XPos, op Op, x, rtype Node) *DynamicTypeAssertExpr {
|
|
n := &DynamicTypeAssertExpr{X: x, RType: rtype}
|
|
n.pos = pos
|
|
n.op = op
|
|
return n
|
|
}
|
|
|
|
func (n *DynamicTypeAssertExpr) SetOp(op Op) {
|
|
switch op {
|
|
default:
|
|
panic(n.no("SetOp " + op.String()))
|
|
case ODYNAMICDOTTYPE, ODYNAMICDOTTYPE2:
|
|
n.op = op
|
|
}
|
|
}
|
|
|
|
// A UnaryExpr is a unary expression Op X,
|
|
// or Op(X) for a builtin function that does not end up being a call.
|
|
type UnaryExpr struct {
|
|
miniExpr
|
|
X Node
|
|
}
|
|
|
|
func NewUnaryExpr(pos src.XPos, op Op, x Node) *UnaryExpr {
|
|
n := &UnaryExpr{X: x}
|
|
n.pos = pos
|
|
n.SetOp(op)
|
|
return n
|
|
}
|
|
|
|
func (n *UnaryExpr) SetOp(op Op) {
|
|
switch op {
|
|
default:
|
|
panic(n.no("SetOp " + op.String()))
|
|
case OBITNOT, ONEG, ONOT, OPLUS, ORECV,
|
|
OCAP, OCLEAR, OCLOSE, OIMAG, OLEN, ONEW, OPANIC, OREAL,
|
|
OCHECKNIL, OCFUNC, OIDATA, OITAB, OSPTR,
|
|
OUNSAFESTRINGDATA, OUNSAFESLICEDATA:
|
|
n.op = op
|
|
}
|
|
}
|
|
|
|
func IsZero(n Node) bool {
|
|
switch n.Op() {
|
|
case ONIL:
|
|
return true
|
|
|
|
case OLITERAL:
|
|
switch u := n.Val(); u.Kind() {
|
|
case constant.String:
|
|
return constant.StringVal(u) == ""
|
|
case constant.Bool:
|
|
return !constant.BoolVal(u)
|
|
default:
|
|
return constant.Sign(u) == 0
|
|
}
|
|
|
|
case OARRAYLIT:
|
|
n := n.(*CompLitExpr)
|
|
for _, n1 := range n.List {
|
|
if n1.Op() == OKEY {
|
|
n1 = n1.(*KeyExpr).Value
|
|
}
|
|
if !IsZero(n1) {
|
|
return false
|
|
}
|
|
}
|
|
return true
|
|
|
|
case OSTRUCTLIT:
|
|
n := n.(*CompLitExpr)
|
|
for _, n1 := range n.List {
|
|
n1 := n1.(*StructKeyExpr)
|
|
if !IsZero(n1.Value) {
|
|
return false
|
|
}
|
|
}
|
|
return true
|
|
}
|
|
|
|
return false
|
|
}
|
|
|
|
// lvalue etc
|
|
func IsAddressable(n Node) bool {
|
|
switch n.Op() {
|
|
case OINDEX:
|
|
n := n.(*IndexExpr)
|
|
if n.X.Type() != nil && n.X.Type().IsArray() {
|
|
return IsAddressable(n.X)
|
|
}
|
|
if n.X.Type() != nil && n.X.Type().IsString() {
|
|
return false
|
|
}
|
|
fallthrough
|
|
case ODEREF, ODOTPTR:
|
|
return true
|
|
|
|
case ODOT:
|
|
n := n.(*SelectorExpr)
|
|
return IsAddressable(n.X)
|
|
|
|
case ONAME:
|
|
n := n.(*Name)
|
|
if n.Class == PFUNC {
|
|
return false
|
|
}
|
|
return true
|
|
|
|
case OLINKSYMOFFSET:
|
|
return true
|
|
}
|
|
|
|
return false
|
|
}
|
|
|
|
// StaticValue analyzes n to find the earliest expression that always
|
|
// evaluates to the same value as n, which might be from an enclosing
|
|
// function.
|
|
//
|
|
// For example, given:
|
|
//
|
|
// var x int = g()
|
|
// func() {
|
|
// y := x
|
|
// *p = int(y)
|
|
// }
|
|
//
|
|
// calling StaticValue on the "int(y)" expression returns the outer
|
|
// "g()" expression.
|
|
//
|
|
// NOTE: StaticValue can return a result with a different type than
|
|
// n's type because it can traverse through OCONVNOP operations.
|
|
// TODO: consider reapplying OCONVNOP operations to the result. See https://go.dev/cl/676517.
|
|
func StaticValue(n Node) Node {
|
|
for {
|
|
switch n1 := n.(type) {
|
|
case *ConvExpr:
|
|
if n1.Op() == OCONVNOP {
|
|
n = n1.X
|
|
continue
|
|
}
|
|
case *InlinedCallExpr:
|
|
if n1.Op() == OINLCALL {
|
|
n = n1.SingleResult()
|
|
continue
|
|
}
|
|
case *ParenExpr:
|
|
n = n1.X
|
|
continue
|
|
}
|
|
|
|
n1 := staticValue1(n)
|
|
if n1 == nil {
|
|
return n
|
|
}
|
|
n = n1
|
|
}
|
|
}
|
|
|
|
func staticValue1(nn Node) Node {
|
|
if nn.Op() != ONAME {
|
|
return nil
|
|
}
|
|
n := nn.(*Name).Canonical()
|
|
if n.Class != PAUTO {
|
|
return nil
|
|
}
|
|
|
|
defn := n.Defn
|
|
if defn == nil {
|
|
return nil
|
|
}
|
|
|
|
var rhs Node
|
|
FindRHS:
|
|
switch defn.Op() {
|
|
case OAS:
|
|
defn := defn.(*AssignStmt)
|
|
rhs = defn.Y
|
|
case OAS2:
|
|
defn := defn.(*AssignListStmt)
|
|
for i, lhs := range defn.Lhs {
|
|
if lhs == n {
|
|
rhs = defn.Rhs[i]
|
|
break FindRHS
|
|
}
|
|
}
|
|
base.FatalfAt(defn.Pos(), "%v missing from LHS of %v", n, defn)
|
|
default:
|
|
return nil
|
|
}
|
|
if rhs == nil {
|
|
base.FatalfAt(defn.Pos(), "RHS is nil: %v", defn)
|
|
}
|
|
|
|
if Reassigned(n) {
|
|
return nil
|
|
}
|
|
|
|
return rhs
|
|
}
|
|
|
|
// Reassigned takes an ONAME node, walks the function in which it is
|
|
// defined, and returns a boolean indicating whether the name has any
|
|
// assignments other than its declaration.
|
|
// NB: global variables are always considered to be re-assigned.
|
|
// TODO: handle initial declaration not including an assignment and
|
|
// followed by a single assignment?
|
|
// NOTE: any changes made here should also be made in the corresponding
|
|
// code in the ReassignOracle.Init method.
|
|
func Reassigned(name *Name) bool {
|
|
if name.Op() != ONAME {
|
|
base.Fatalf("reassigned %v", name)
|
|
}
|
|
// no way to reliably check for no-reassignment of globals, assume it can be
|
|
if name.Curfn == nil {
|
|
return true
|
|
}
|
|
|
|
if name.Addrtaken() {
|
|
return true // conservatively assume it's reassigned indirectly
|
|
}
|
|
|
|
// TODO(mdempsky): This is inefficient and becoming increasingly
|
|
// unwieldy. Figure out a way to generalize escape analysis's
|
|
// reassignment detection for use by inlining and devirtualization.
|
|
|
|
// isName reports whether n is a reference to name.
|
|
isName := func(x Node) bool {
|
|
if x == nil {
|
|
return false
|
|
}
|
|
n, ok := OuterValue(x).(*Name)
|
|
return ok && n.Canonical() == name
|
|
}
|
|
|
|
var do func(n Node) bool
|
|
do = func(n Node) bool {
|
|
switch n.Op() {
|
|
case OAS:
|
|
n := n.(*AssignStmt)
|
|
if isName(n.X) && n != name.Defn {
|
|
return true
|
|
}
|
|
case OAS2, OAS2FUNC, OAS2MAPR, OAS2DOTTYPE, OAS2RECV, OSELRECV2:
|
|
n := n.(*AssignListStmt)
|
|
for _, p := range n.Lhs {
|
|
if isName(p) && n != name.Defn {
|
|
return true
|
|
}
|
|
}
|
|
case OASOP:
|
|
n := n.(*AssignOpStmt)
|
|
if isName(n.X) {
|
|
return true
|
|
}
|
|
case OADDR:
|
|
n := n.(*AddrExpr)
|
|
if isName(n.X) {
|
|
base.FatalfAt(n.Pos(), "%v not marked addrtaken", name)
|
|
}
|
|
case ORANGE:
|
|
n := n.(*RangeStmt)
|
|
if isName(n.Key) || isName(n.Value) {
|
|
return true
|
|
}
|
|
case OCLOSURE:
|
|
n := n.(*ClosureExpr)
|
|
if Any(n.Func, do) {
|
|
return true
|
|
}
|
|
}
|
|
return false
|
|
}
|
|
return Any(name.Curfn, do)
|
|
}
|
|
|
|
// StaticCalleeName returns the ONAME/PFUNC for n, if known.
|
|
func StaticCalleeName(n Node) *Name {
|
|
switch n.Op() {
|
|
case OMETHEXPR:
|
|
n := n.(*SelectorExpr)
|
|
return MethodExprName(n)
|
|
case ONAME:
|
|
n := n.(*Name)
|
|
if n.Class == PFUNC {
|
|
return n
|
|
}
|
|
case OCLOSURE:
|
|
return n.(*ClosureExpr).Func.Nname
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// IsIntrinsicCall reports whether the compiler back end will treat the call as an intrinsic operation.
|
|
var IsIntrinsicCall = func(*CallExpr) bool { return false }
|
|
|
|
// IsIntrinsicSym reports whether the compiler back end will treat a call to this symbol as an intrinsic operation.
|
|
var IsIntrinsicSym = func(*types.Sym) bool { return false }
|
|
|
|
// SameSafeExpr checks whether it is safe to reuse one of l and r
|
|
// instead of computing both. SameSafeExpr assumes that l and r are
|
|
// used in the same statement or expression. In order for it to be
|
|
// safe to reuse l or r, they must:
|
|
// - be the same expression
|
|
// - not have side-effects (no function calls, no channel ops);
|
|
// however, panics are ok
|
|
// - not cause inappropriate aliasing; e.g. two string to []byte
|
|
// conversions, must result in two distinct slices
|
|
//
|
|
// The handling of OINDEXMAP is subtle. OINDEXMAP can occur both
|
|
// as an lvalue (map assignment) and an rvalue (map access). This is
|
|
// currently OK, since the only place SameSafeExpr gets used on an
|
|
// lvalue expression is for OSLICE and OAPPEND optimizations, and it
|
|
// is correct in those settings.
|
|
func SameSafeExpr(l Node, r Node) bool {
|
|
for l.Op() == OCONVNOP {
|
|
l = l.(*ConvExpr).X
|
|
}
|
|
for r.Op() == OCONVNOP {
|
|
r = r.(*ConvExpr).X
|
|
}
|
|
if l.Op() != r.Op() || !types.Identical(l.Type(), r.Type()) {
|
|
return false
|
|
}
|
|
|
|
switch l.Op() {
|
|
case ONAME:
|
|
return l == r
|
|
|
|
case ODOT, ODOTPTR:
|
|
l := l.(*SelectorExpr)
|
|
r := r.(*SelectorExpr)
|
|
return l.Sel != nil && r.Sel != nil && l.Sel == r.Sel && SameSafeExpr(l.X, r.X)
|
|
|
|
case ODEREF:
|
|
l := l.(*StarExpr)
|
|
r := r.(*StarExpr)
|
|
return SameSafeExpr(l.X, r.X)
|
|
|
|
case ONOT, OBITNOT, OPLUS, ONEG:
|
|
l := l.(*UnaryExpr)
|
|
r := r.(*UnaryExpr)
|
|
return SameSafeExpr(l.X, r.X)
|
|
|
|
case OCONV:
|
|
l := l.(*ConvExpr)
|
|
r := r.(*ConvExpr)
|
|
// Some conversions can't be reused, such as []byte(str).
|
|
// Allow only numeric-ish types. This is a bit conservative.
|
|
return types.IsSimple[l.Type().Kind()] && SameSafeExpr(l.X, r.X)
|
|
|
|
case OINDEX, OINDEXMAP:
|
|
l := l.(*IndexExpr)
|
|
r := r.(*IndexExpr)
|
|
return SameSafeExpr(l.X, r.X) && SameSafeExpr(l.Index, r.Index)
|
|
|
|
case OADD, OSUB, OOR, OXOR, OMUL, OLSH, ORSH, OAND, OANDNOT, ODIV, OMOD:
|
|
l := l.(*BinaryExpr)
|
|
r := r.(*BinaryExpr)
|
|
return SameSafeExpr(l.X, r.X) && SameSafeExpr(l.Y, r.Y)
|
|
|
|
case OLITERAL:
|
|
return constant.Compare(l.Val(), token.EQL, r.Val())
|
|
|
|
case ONIL:
|
|
return true
|
|
}
|
|
|
|
return false
|
|
}
|
|
|
|
// ShouldCheckPtr reports whether pointer checking should be enabled for
|
|
// function fn at a given level. See debugHelpFooter for defined
|
|
// levels.
|
|
func ShouldCheckPtr(fn *Func, level int) bool {
|
|
return base.Debug.Checkptr >= level && fn.Pragma&NoCheckPtr == 0
|
|
}
|
|
|
|
// ShouldAsanCheckPtr reports whether pointer checking should be enabled for
|
|
// function fn when -asan is enabled.
|
|
func ShouldAsanCheckPtr(fn *Func) bool {
|
|
return base.Flag.ASan && fn.Pragma&NoCheckPtr == 0
|
|
}
|
|
|
|
// IsReflectHeaderDataField reports whether l is an expression p.Data
|
|
// where p has type reflect.SliceHeader or reflect.StringHeader.
|
|
func IsReflectHeaderDataField(l Node) bool {
|
|
if l.Type() != types.Types[types.TUINTPTR] {
|
|
return false
|
|
}
|
|
|
|
var tsym *types.Sym
|
|
switch l.Op() {
|
|
case ODOT:
|
|
l := l.(*SelectorExpr)
|
|
tsym = l.X.Type().Sym()
|
|
case ODOTPTR:
|
|
l := l.(*SelectorExpr)
|
|
tsym = l.X.Type().Elem().Sym()
|
|
default:
|
|
return false
|
|
}
|
|
|
|
if tsym == nil || l.Sym().Name != "Data" || tsym.Pkg.Path != "reflect" {
|
|
return false
|
|
}
|
|
return tsym.Name == "SliceHeader" || tsym.Name == "StringHeader"
|
|
}
|
|
|
|
func ParamNames(ft *types.Type) []Node {
|
|
args := make([]Node, ft.NumParams())
|
|
for i, f := range ft.Params() {
|
|
args[i] = f.Nname.(*Name)
|
|
}
|
|
return args
|
|
}
|
|
|
|
func RecvParamNames(ft *types.Type) []Node {
|
|
args := make([]Node, ft.NumRecvs()+ft.NumParams())
|
|
for i, f := range ft.RecvParams() {
|
|
args[i] = f.Nname.(*Name)
|
|
}
|
|
return args
|
|
}
|
|
|
|
// MethodSym returns the method symbol representing a method name
|
|
// associated with a specific receiver type.
|
|
//
|
|
// Method symbols can be used to distinguish the same method appearing
|
|
// in different method sets. For example, T.M and (*T).M have distinct
|
|
// method symbols.
|
|
//
|
|
// The returned symbol will be marked as a function.
|
|
func MethodSym(recv *types.Type, msym *types.Sym) *types.Sym {
|
|
sym := MethodSymSuffix(recv, msym, "")
|
|
sym.SetFunc(true)
|
|
return sym
|
|
}
|
|
|
|
// MethodSymSuffix is like MethodSym, but allows attaching a
|
|
// distinguisher suffix. To avoid collisions, the suffix must not
|
|
// start with a letter, number, or period.
|
|
func MethodSymSuffix(recv *types.Type, msym *types.Sym, suffix string) *types.Sym {
|
|
if msym.IsBlank() {
|
|
base.Fatalf("blank method name")
|
|
}
|
|
|
|
rsym := recv.Sym()
|
|
if recv.IsPtr() {
|
|
if rsym != nil {
|
|
base.Fatalf("declared pointer receiver type: %v", recv)
|
|
}
|
|
rsym = recv.Elem().Sym()
|
|
}
|
|
|
|
// Find the package the receiver type appeared in. For
|
|
// anonymous receiver types (i.e., anonymous structs with
|
|
// embedded fields), use the "go" pseudo-package instead.
|
|
rpkg := Pkgs.Go
|
|
if rsym != nil {
|
|
rpkg = rsym.Pkg
|
|
}
|
|
|
|
var b bytes.Buffer
|
|
if recv.IsPtr() {
|
|
// The parentheses aren't really necessary, but
|
|
// they're pretty traditional at this point.
|
|
fmt.Fprintf(&b, "(%-S)", recv)
|
|
} else {
|
|
fmt.Fprintf(&b, "%-S", recv)
|
|
}
|
|
|
|
// A particular receiver type may have multiple non-exported
|
|
// methods with the same name. To disambiguate them, include a
|
|
// package qualifier for names that came from a different
|
|
// package than the receiver type.
|
|
if !types.IsExported(msym.Name) && msym.Pkg != rpkg {
|
|
b.WriteString(".")
|
|
b.WriteString(msym.Pkg.Prefix)
|
|
}
|
|
|
|
b.WriteString(".")
|
|
b.WriteString(msym.Name)
|
|
b.WriteString(suffix)
|
|
return rpkg.LookupBytes(b.Bytes())
|
|
}
|
|
|
|
// LookupMethodSelector returns the types.Sym of the selector for a method
|
|
// named in local symbol name, as well as the types.Sym of the receiver.
|
|
//
|
|
// TODO(prattmic): this does not attempt to handle method suffixes (wrappers).
|
|
func LookupMethodSelector(pkg *types.Pkg, name string) (typ, meth *types.Sym, err error) {
|
|
typeName, methName := splitType(name)
|
|
if typeName == "" {
|
|
return nil, nil, fmt.Errorf("%s doesn't contain type split", name)
|
|
}
|
|
|
|
if len(typeName) > 3 && typeName[:2] == "(*" && typeName[len(typeName)-1] == ')' {
|
|
// Symbol name is for a pointer receiver method. We just want
|
|
// the base type name.
|
|
typeName = typeName[2 : len(typeName)-1]
|
|
}
|
|
|
|
typ = pkg.Lookup(typeName)
|
|
meth = pkg.Selector(methName)
|
|
return typ, meth, nil
|
|
}
|
|
|
|
// splitType splits a local symbol name into type and method (fn). If this a
|
|
// free function, typ == "".
|
|
//
|
|
// N.B. closures and methods can be ambiguous (e.g., bar.func1). These cases
|
|
// are returned as methods.
|
|
func splitType(name string) (typ, fn string) {
|
|
// Types are split on the first dot, ignoring everything inside
|
|
// brackets (instantiation of type parameter, usually including
|
|
// "go.shape").
|
|
bracket := 0
|
|
for i, r := range name {
|
|
if r == '.' && bracket == 0 {
|
|
return name[:i], name[i+1:]
|
|
}
|
|
if r == '[' {
|
|
bracket++
|
|
}
|
|
if r == ']' {
|
|
bracket--
|
|
}
|
|
}
|
|
return "", name
|
|
}
|
|
|
|
// MethodExprName returns the ONAME representing the method
|
|
// referenced by expression n, which must be a method selector,
|
|
// method expression, or method value.
|
|
func MethodExprName(n Node) *Name {
|
|
name, _ := MethodExprFunc(n).Nname.(*Name)
|
|
return name
|
|
}
|
|
|
|
// MethodExprFunc is like MethodExprName, but returns the types.Field instead.
|
|
func MethodExprFunc(n Node) *types.Field {
|
|
switch n.Op() {
|
|
case ODOTMETH, OMETHEXPR, OMETHVALUE:
|
|
return n.(*SelectorExpr).Selection
|
|
}
|
|
base.Fatalf("unexpected node: %v (%v)", n, n.Op())
|
|
panic("unreachable")
|
|
}
|