@@ -1847,6 +1847,12 @@ bool AtomicExpand::expandAtomicOpToLibcall(
18471847 Args.push_back (ConstantInt::get (DL.getIntPtrType (Ctx), Size));
18481848 }
18491849
1850+ bool bShouldDisableLifetimeMarker = false ;
1851+
1852+ if (I->getParent () && I->getParent ()->getParent () && I->getParent ()->getParent ()->hasSEHOrCXXSEH ()) {
1853+ bShouldDisableLifetimeMarker = true ;
1854+ }
1855+
18501856 // 'ptr' argument.
18511857 // note: This assumes all address spaces share a common libfunc
18521858 // implementation and that addresses are convertable. For systems without
@@ -1860,9 +1866,11 @@ bool AtomicExpand::expandAtomicOpToLibcall(
18601866 if (CASExpected) {
18611867 AllocaCASExpected = AllocaBuilder.CreateAlloca (CASExpected->getType ());
18621868 AllocaCASExpected->setAlignment (AllocaAlignment);
1863- #ifndef _WIN32
1864- Builder.CreateLifetimeStart (AllocaCASExpected, SizeVal64);
1865- #endif
1869+ if (!bShouldDisableLifetimeMarker) {
1870+
1871+ Builder.CreateLifetimeStart (AllocaCASExpected, SizeVal64);
1872+ }
1873+
18661874 Builder.CreateAlignedStore (CASExpected, AllocaCASExpected, AllocaAlignment);
18671875 Args.push_back (AllocaCASExpected);
18681876 }
@@ -1876,9 +1884,10 @@ bool AtomicExpand::expandAtomicOpToLibcall(
18761884 } else {
18771885 AllocaValue = AllocaBuilder.CreateAlloca (ValueOperand->getType ());
18781886 AllocaValue->setAlignment (AllocaAlignment);
1879- #ifndef _WIN32
1880- Builder.CreateLifetimeStart (AllocaValue, SizeVal64);
1881- #endif
1887+ if (!bShouldDisableLifetimeMarker) {
1888+ Builder.CreateLifetimeStart (AllocaValue, SizeVal64);
1889+ }
1890+
18821891 Builder.CreateAlignedStore (ValueOperand, AllocaValue, AllocaAlignment);
18831892 Args.push_back (AllocaValue);
18841893 }
@@ -1888,9 +1897,10 @@ bool AtomicExpand::expandAtomicOpToLibcall(
18881897 if (!CASExpected && HasResult && !UseSizedLibcall) {
18891898 AllocaResult = AllocaBuilder.CreateAlloca (I->getType ());
18901899 AllocaResult->setAlignment (AllocaAlignment);
1891- #ifndef _WIN32
1892- Builder.CreateLifetimeStart (AllocaResult, SizeVal64);
1893- #endif
1900+ if (!bShouldDisableLifetimeMarker) {
1901+ Builder.CreateLifetimeStart (AllocaResult, SizeVal64);
1902+ }
1903+
18941904 Args.push_back (AllocaResult);
18951905 }
18961906
@@ -1920,21 +1930,21 @@ bool AtomicExpand::expandAtomicOpToLibcall(
19201930 CallInst *Call = Builder.CreateCall (LibcallFn, Args);
19211931 Call->setAttributes (Attr);
19221932 Value *Result = Call;
1923- # ifndef _WIN32
1924- // And then, extract the results...
1925- if (ValueOperand && !UseSizedLibcall)
1926- Builder.CreateLifetimeEnd (AllocaValue, SizeVal64);
1927- # endif
1933+ if (!bShouldDisableLifetimeMarker) {
1934+ // And then, extract the results...
1935+ if (ValueOperand && !UseSizedLibcall)
1936+ Builder.CreateLifetimeEnd (AllocaValue, SizeVal64);
1937+ }
19281938 if (CASExpected) {
19291939 // The final result from the CAS is {load of 'expected' alloca, bool result
19301940 // from call}
19311941 Type *FinalResultTy = I->getType ();
19321942 Value *V = PoisonValue::get (FinalResultTy);
19331943 Value *ExpectedOut = Builder.CreateAlignedLoad (
19341944 CASExpected->getType (), AllocaCASExpected, AllocaAlignment);
1935- # ifndef _WIN32
1936- Builder.CreateLifetimeEnd (AllocaCASExpected, SizeVal64);
1937- # endif
1945+ if (!bShouldDisableLifetimeMarker) {
1946+ Builder.CreateLifetimeEnd (AllocaCASExpected, SizeVal64);
1947+ }
19381948 V = Builder.CreateInsertValue (V, ExpectedOut, 0 );
19391949 V = Builder.CreateInsertValue (V, Result, 1 );
19401950 I->replaceAllUsesWith (V);
@@ -1945,9 +1955,9 @@ bool AtomicExpand::expandAtomicOpToLibcall(
19451955 else {
19461956 V = Builder.CreateAlignedLoad (I->getType (), AllocaResult,
19471957 AllocaAlignment);
1948- # ifndef _WIN32
1949- Builder.CreateLifetimeEnd (AllocaResult, SizeVal64);
1950- # endif
1958+ if (!bShouldDisableLifetimeMarker) {
1959+ Builder.CreateLifetimeEnd (AllocaResult, SizeVal64);
1960+ }
19511961 }
19521962 I->replaceAllUsesWith (V);
19531963 }
0 commit comments