@@ -11,7 +11,7 @@ use rustc_hir as hir;
1111use rustc_hir:: lang_items:: LangItem ;
1212use rustc_index:: bit_set:: BitSet ;
1313use rustc_index:: vec:: { Idx , IndexVec } ;
14- use rustc_session:: { DataTypeKind , FieldInfo , SizeKind , VariantInfo } ;
14+ use rustc_session:: { config :: OptLevel , DataTypeKind , FieldInfo , SizeKind , VariantInfo } ;
1515use rustc_span:: symbol:: { Ident , Symbol } ;
1616use rustc_span:: DUMMY_SP ;
1717use rustc_target:: abi:: call:: {
@@ -2318,23 +2318,30 @@ where
23182318 ty:: Ref ( _, ty, mt) if offset. bytes ( ) == 0 => {
23192319 let address_space = addr_space_of_ty ( ty) ;
23202320 let tcx = cx. tcx ( ) ;
2321- let kind = match mt {
2322- hir:: Mutability :: Not => {
2323- if ty. is_freeze ( tcx. at ( DUMMY_SP ) , cx. param_env ( ) ) {
2324- PointerKind :: Frozen
2325- } else {
2326- PointerKind :: Shared
2321+ let kind = if tcx. sess . opts . optimize == OptLevel :: No {
2322+ // Use conservative pointer kind if not optimizing. This saves us the
2323+ // Freeze/Unpin queries, and can save time in the codegen backend (noalias
2324+ // attributes in LLVM have compile-time cost even in unoptimized builds).
2325+ PointerKind :: Shared
2326+ } else {
2327+ match mt {
2328+ hir:: Mutability :: Not => {
2329+ if ty. is_freeze ( tcx. at ( DUMMY_SP ) , cx. param_env ( ) ) {
2330+ PointerKind :: Frozen
2331+ } else {
2332+ PointerKind :: Shared
2333+ }
23272334 }
2328- }
2329- hir :: Mutability :: Mut => {
2330- // References to self-referential structures should not be considered
2331- // noalias, as another pointer to the structure can be obtained, that
2332- // is not based-on the original reference. We consider all !Unpin
2333- // types to be potentially self-referential here.
2334- if ty . is_unpin ( tcx . at ( DUMMY_SP ) , cx . param_env ( ) ) {
2335- PointerKind :: UniqueBorrowed
2336- } else {
2337- PointerKind :: Shared
2335+ hir :: Mutability :: Mut => {
2336+ // References to self-referential structures should not be considered
2337+ // noalias, as another pointer to the structure can be obtained, that
2338+ // is not based-on the original reference. We consider all !Unpin
2339+ // types to be potentially self-referential here.
2340+ if ty . is_unpin ( tcx . at ( DUMMY_SP ) , cx . param_env ( ) ) {
2341+ PointerKind :: UniqueBorrowed
2342+ } else {
2343+ PointerKind :: Shared
2344+ }
23382345 }
23392346 }
23402347 } ;
0 commit comments