testuite: fix libtdc++ libatomic flags
[official-gcc.git] / libgo / go / reflect / eqtype_aix_gccgo.go
blob7afbf10ad6db58dff6d876847572ffeb45a0cc0f
1 // Copyright 2020 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
5 //+build aix,gccgo
7 // AIX linker isn't able to merge identical type descriptors coming from
8 // different objects. Thus, two rtypes might have two different pointers
9 // even if they are the same. Thus, instead of pointer equality, string
10 // field is checked.
12 package reflect
14 import (
15 "sync"
18 // rtypeEqual returns true if both rtypes are identical.
19 func rtypeEqual(t1, t2 *rtype) bool {
20 switch {
21 case t1 == t2:
22 return true
23 case t1 == nil || t2 == nil:
24 return false
25 case t1.kind != t2.kind || t1.hash != t2.hash:
26 return false
27 default:
28 return t1.String() == t2.String()
32 // typeEqual returns true if both Types are identical.
33 func typeEqual(t1, t2 Type) bool {
34 return rtypeEqual(t1.common(), t2.common())
37 // toType converts from a *rtype to a Type that can be returned
38 // to the client of package reflect. The only concern is that
39 // a nil *rtype must be replaced by a nil Type.
40 // On AIX, as type duplications can occur, it also ensure that
41 // multiple *rtype for the same type are coalesced into a single
42 // Type.
44 var canonicalType = make(map[string]Type)
46 var canonicalTypeLock sync.RWMutex
48 func canonicalize(t Type) Type {
49 if t == nil {
50 return nil
52 s := t.rawString()
53 canonicalTypeLock.RLock()
54 if r, ok := canonicalType[s]; ok {
55 canonicalTypeLock.RUnlock()
56 return r
58 canonicalTypeLock.RUnlock()
59 canonicalTypeLock.Lock()
60 if r, ok := canonicalType[s]; ok {
61 canonicalTypeLock.Unlock()
62 return r
64 canonicalType[s] = t
65 canonicalTypeLock.Unlock()
66 return t
69 func toType(p *rtype) Type {
70 if p == nil {
71 return nil
73 return canonicalize(p)