Skip to content

Commit 668ee3f

Browse files
authored
[clang] Default to -fno-sized-deallocation for AIX (llvm#97076)
Some `libc++` LIT test cases and user code define their own version of `operator delete` that are not sized. With `-fno-sized-deallocation`, destructors call the non-sized `operator delete` and it will be resolved to the user defined version. However, with `-fsized-deallocation`, destructors will call the sized `operator delete` which will be resolved to the weak definition in `libc++abi` because the user code does not define the corresponding sized version. The `libc++abi` sized `operator delete` in turn calls the non-sized version of `operator delete` of the same shared object inside `libc++abi` instead of the user defined version on AIX because runtime linking is not the default for AIX and therefore, fails the tests or user code. This patch sets `-fno-sized-deallocation` as the default for AIX if neither `-fsize-deallocation` nor `-fno-sized-deallocation` is explicitly set, similar to what is done for ZOS.
1 parent 7c50187 commit 668ee3f

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

clang/lib/Driver/ToolChains/AIX.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -551,6 +551,12 @@ void AIX::addClangTargetOptions(
551551
if (Args.hasFlag(options::OPT_fxl_pragma_pack,
552552
options::OPT_fno_xl_pragma_pack, true))
553553
CC1Args.push_back("-fxl-pragma-pack");
554+
555+
// Pass "-fno-sized-deallocation" only when the user hasn't manually enabled
556+
// or disabled sized deallocations.
557+
if (!Args.getLastArgNoClaim(options::OPT_fsized_deallocation,
558+
options::OPT_fno_sized_deallocation))
559+
CC1Args.push_back("-fno-sized-deallocation");
554560
}
555561

556562
void AIX::addProfileRTLibs(const llvm::opt::ArgList &Args,

clang/unittests/StaticAnalyzer/CallEventTest.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,12 @@ TEST(CXXDeallocatorCall, SimpleDestructor) {
7676
}
7777
)",
7878
Diags));
79+
#if defined(_AIX) || defined(__MVS__)
80+
// AIX and ZOS default to -fno-sized-deallocation.
81+
EXPECT_EQ(Diags, "test.CXXDeallocator: NumArgs: 1\n");
82+
#else
7983
EXPECT_EQ(Diags, "test.CXXDeallocator: NumArgs: 2\n");
84+
#endif
8085
}
8186

8287
} // namespace

0 commit comments

Comments
 (0)