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