@@ -2507,6 +2507,44 @@ static bool checkStrictFP(const Function &Caller, const Function &Callee) {
2507
2507
Caller.getAttributes ().hasFnAttr (Attribute::StrictFP);
2508
2508
}
2509
2509
2510
+ static bool checkSections (const Function &Caller, const Function &Callee) {
2511
+ // Implement MSVC compatible cross-section inlining rules
2512
+ StringRef CallerSection = Caller.getSection ();
2513
+ StringRef CalleeSection = Callee.getSection ();
2514
+
2515
+ // sections match, inline ok
2516
+ if (!CallerSection.compare (CalleeSection))
2517
+ return true ;
2518
+
2519
+ bool isCallerPaged = CallerSection.starts_with (" PAGE" );
2520
+ bool isCalleePaged = CalleeSection.starts_with (" PAGE" );
2521
+
2522
+ // Prevent inlining of non-paged code into a paged caller
2523
+ // Prevent inlining of paged code into non-paged caller
2524
+ // Section names are compared only before the '$' separator if present
2525
+
2526
+ if (isCallerPaged) {
2527
+ size_t CallerComparable = CallerSection.size ();
2528
+ size_t CalleeComparable = CalleeSection.size ();
2529
+ size_t CallerSep = CallerSection.find (' $' );
2530
+ size_t CalleeSep = CalleeSection.find (' $' );
2531
+
2532
+ if (CallerSep != StringRef::npos)
2533
+ CallerComparable = CallerSep;
2534
+ if (CalleeSep != StringRef::npos)
2535
+ CalleeComparable = CalleeSep;
2536
+ if (CallerComparable != CalleeComparable)
2537
+ return false ;
2538
+
2539
+ StringRef CallerComparableSection = CallerSection.substr (0 , CallerComparable);
2540
+ StringRef CalleeComparableSection = CalleeSection.substr (0 , CallerComparable);
2541
+ return !CallerComparableSection.compare (CalleeComparableSection);
2542
+ } else if (isCalleePaged)
2543
+ return false ;
2544
+
2545
+ return true ;
2546
+ }
2547
+
2510
2548
template <typename AttrClass>
2511
2549
static bool isEqual (const Function &Caller, const Function &Callee) {
2512
2550
return Caller.getFnAttribute (AttrClass::getKind ()) ==
0 commit comments