[clang] [llvm] [ObjC][LTO] Propagate constant ivar offsets across ThinLTO and FullLTO (PR #205970)
Matt Arsenault via cfe-commits
cfe-commits at lists.llvm.org
Wed Jul 8 07:43:16 PDT 2026
================
@@ -0,0 +1,141 @@
+; Test cross-module ThinLTO sliding when Sub's compile-time instanceStart
+; is stale due to Super's hidden extension ivar.
+;
+; Hierarchy:
+; NSObject
+; `- Super
+; int x; // x at offset 8
+; int hidden; // hidden at offset 12 (extension)
+; `- Sub
+; int y; // y compiled at 12, slid to 16
+;
+; RUN: rm -rf %t && split-file %s %t
+; RUN: opt -module-summary %t/sub.ll -o %t/sub.bc
+; RUN: opt -module-summary %t/super.ll -o %t/super.bc
+; RUN: llvm-lto2 run %t/sub.bc %t/super.bc -save-temps -o %t/out \
+; RUN: -r=%t/sub.bc,_OBJC_CLASS_$_Sub,plx \
+; RUN: -r=%t/sub.bc,_OBJC_CLASS_$_Super, \
+; RUN: -r=%t/sub.bc,_OBJC_IVAR_$_Sub.y,plx \
+; RUN: -r=%t/sub.bc,_OBJC_METACLASS_$_NSObject, \
+; RUN: -r=%t/sub.bc,_OBJC_METACLASS_$_Sub,plx \
+; RUN: -r=%t/sub.bc,_OBJC_METACLASS_$_Super, \
+; RUN: -r=%t/sub.bc,__objc_empty_cache, \
+; RUN: -r=%t/super.bc,_OBJC_CLASS_$_NSObject, \
+; RUN: -r=%t/super.bc,_OBJC_CLASS_$_Super,plx \
+; RUN: -r=%t/super.bc,_OBJC_IVAR_$_Super.hidden,plx \
+; RUN: -r=%t/super.bc,_OBJC_IVAR_$_Super.x,plx \
+; RUN: -r=%t/super.bc,_OBJC_METACLASS_$_NSObject, \
+; RUN: -r=%t/super.bc,_OBJC_METACLASS_$_Super,plx \
+; RUN: -r=%t/super.bc,__objc_empty_cache,
+;
+; Sub ivar offset should be slid from 12 to 16, and marked constant.
+; RUN: llvm-dis %t/out.1.4.opt.bc -o - | FileCheck %s --check-prefix=SUB
+; Super ivars are already constant and should be unchanged.
+; RUN: llvm-dis %t/out.2.4.opt.bc -o - | FileCheck %s --check-prefix=SUPER
+;
+; SUB: @"OBJC_IVAR_$_Sub.y" = {{.*}}constant i64 16
+; SUPER: @"OBJC_IVAR_$_Super.x" = {{.*}}constant i64 8
+; SUPER: @"OBJC_IVAR_$_Super.hidden" = {{.*}}constant i64 12
+
+; Segments:
+; Super.m / Sub.m - ingredients (requires Darwin SDK to regenerate)
+; gen - refresher
+; super.ll / sub.ll - per-module IR, used by ThinLTO path
+
+;--- Super.m
+#import <objc/NSObject.h>
+ at interface Super : NSObject { int x; } @end
+ at interface Super () { int hidden; } @end
+ at implementation Super @end
+
+;--- Sub.m
+#import <objc/NSObject.h>
+ at interface Super : NSObject { int x; } @end
+ at interface Sub : Super { int y; } @end
+ at implementation Sub @end
+
+;--- gen
+clang -target x86_64-apple-macosx10.15 -fobjc-runtime=macosx-10.15 -S -emit-llvm -isysroot $(xcrun --show-sdk-path) Super.m -o super.ll
+clang -target x86_64-apple-macosx10.15 -fobjc-runtime=macosx-10.15 -S -emit-llvm -isysroot $(xcrun --show-sdk-path) Sub.m -o sub.ll
+cat super.ll
+echo ';--- sub.ll'
+cat sub.ll
+;--- super.ll
+; ModuleID = 'Super.m'
+source_filename = "Super.m"
+target datalayout = "e-m:o-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128"
----------------
arsenm wrote:
Remove unnecessary comments and annotates
https://github.com/llvm/llvm-project/pull/205970
More information about the cfe-commits
mailing list