File tree 3 files changed +26
-1
lines changed 3 files changed +26
-1
lines changed Original file line number Diff line number Diff line change @@ -59,6 +59,7 @@ func Test28896(t *testing.T) { test28896(t) }
59
59
func Test30065 (t * testing.T ) { test30065 (t ) }
60
60
func Test32579 (t * testing.T ) { test32579 (t ) }
61
61
func Test31891 (t * testing.T ) { test31891 (t ) }
62
+ func Test45451 (t * testing.T ) { test45451 (t ) }
62
63
func TestAlign (t * testing.T ) { testAlign (t ) }
63
64
func TestAtol (t * testing.T ) { testAtol (t ) }
64
65
func TestBlocking (t * testing.T ) { testBlocking (t ) }
Original file line number Diff line number Diff line change @@ -912,6 +912,9 @@ void cFunc37033(uintptr_t handle) { GoFunc37033(handle); }
912
912
enum Enum40494 { X_40494 };
913
913
union Union40494 { int x; };
914
914
void issue40494(enum Enum40494 e, union Union40494* up) {}
915
+
916
+ // Issue 45451, bad handling of go:notinheap types.
917
+ typedef struct issue45451Undefined issue45451;
915
918
*/
916
919
import "C"
917
920
@@ -2266,3 +2269,19 @@ var issue39877 *C.void = nil
2266
2269
func Issue40494 () {
2267
2270
C .issue40494 (C .enum_Enum40494 (C .X_40494 ), (* C .union_Union40494 )(nil ))
2268
2271
}
2272
+
2273
+ // Issue 45451.
2274
+ func test45451 (t * testing.T ) {
2275
+ var u * C.issue45451
2276
+ typ := reflect .ValueOf (u ).Type ().Elem ()
2277
+
2278
+ // The type is undefined in C so allocating it should panic.
2279
+ defer func () {
2280
+ if r := recover (); r == nil {
2281
+ t .Error ("expected panic" )
2282
+ }
2283
+ }()
2284
+
2285
+ _ = reflect .New (typ )
2286
+ t .Errorf ("reflect.New(%v) should have panicked" , typ )
2287
+ }
Original file line number Diff line number Diff line change @@ -2702,9 +2702,14 @@ func New(typ Type) Value {
2702
2702
panic ("reflect: New(nil)" )
2703
2703
}
2704
2704
t := typ .(* rtype )
2705
+ pt := t .ptrTo ()
2706
+ if ifaceIndir (pt ) {
2707
+ // This is a pointer to a go:notinheap type.
2708
+ panic ("reflect: New of type that may not be allocated in heap (possibly undefined cgo C type)" )
2709
+ }
2705
2710
ptr := unsafe_New (t )
2706
2711
fl := flag (Ptr )
2707
- return Value {t . ptrTo () , ptr , fl }
2712
+ return Value {pt , ptr , fl }
2708
2713
}
2709
2714
2710
2715
// NewAt returns a Value representing a pointer to a value of the
You can’t perform that action at this time.
0 commit comments