This is an archive of the discontinued LLVM Phabricator instance.

[ADT][CMake][AutoConf] fail-fast iterators for DenseMap
ClosedPublic

Authored by sanjoy on Mar 15 2015, 10:48 PM.

Details

Summary

This is a re-do of D7931 with the following changes:

  • the EpochTracker class is now conditional on LLVM_ENABLE_FAIL_FAST_ITERATORS and not NDEBUG.
  • The most significant change: LLVM_ENABLE_FAIL_FAST_ITERATORS can be forced to be set or unset independent of NDEBUG. By default, cmake and autoconf set it (thus enabling fail-fast iterators) for with-asserts builds and unset it for without-asserts builds.

With these changes, projects that require ABI compatibility between
defined(NDEBUG) builds and !defined(NDEBUG) builds can get that by
clamping LLVM_ENABLE_FAIL_FAST_ITERATORS to on or off.

Minor changes from D7931

  • HandleBase::getEpochAddress returns a void * to emphasise that the result is for comparison, not derefernecing.
  • HandleBase::getEpochAddress was missing in the fail-fast-disabled version of HandleBase. This was not a problem earlier since the function is only called from asserts and when asserts were enabled, we'd always choose the fail-fast-enabled version of HandleBase. Since this is no longer the case (a with-asserts build may be using the fail-fast-disabled version of HandleBase), the missing method shows up as an obvious compiler error.

Original summary for D7931:
This patch is an attempt at making DenseMapIterators "fail-fast".
Fail-fast iterators that have been invalidated due to insertion into
the host DenseMap deterministically trip an assert (in debug mode)
on access, instead of non-deterministically hitting memory corruption
issues.

Diff Detail

Event Timeline

sanjoy updated this revision to Diff 22011.Mar 15 2015, 10:48 PM
sanjoy retitled this revision from to [ADT][CMake][AutoConf] fail-fast iterators for DenseMap.
sanjoy updated this object.
sanjoy edited the test plan for this revision. (Show Details)
sanjoy added reviewers: chandlerc, dexonsmith, rnk, zturner.
sanjoy added a subscriber: Unknown Object (MLST).
zturner edited edge metadata.Mar 16 2015, 9:04 AM

If I understand correctly, this broke before because LLDB would redefine
_NDEBUG sometimes, but not other times when including clang headers.

Now, since this isn't based on _NDEBUG, this is no longer an issue. If so,
looks good to me.

The configure portions are OK with me.

-eric

rnk edited edge metadata.Mar 16 2015, 11:04 AM

This seems like a reasonably good compromise. I'd really like to have this iterator invalidation enabled when assertions are enabled, but we have the ability to flip it off when ABI compatibility is important. Being ABI incompatible by default is really just acknowledging that LLVM's ABI isn't very stable.

Are there any more places we should be documenting this check? http://llvm.org/docs/ReleaseProcess.html or http://lldb.llvm.org/build.html? I know that Chromium for example uses a Release+Asserts build of Clang. This might be too much overhead for them.

LLDB for example might want to have a check like:

if (NOT LLVM_FAIL_FAST_ITERATORS STREQUAL "FORCE_OFF")
  message(FATAL_ERROR "LLDB requires a stable LLVM ABI, set LLVM_FAIL_FAST_ITERATORS to FORCE_OFF")
endif()

Are there any more places we should be documenting this check? http://llvm.org/docs/ReleaseProcess.html or http://lldb.llvm.org/build.html? I know that Chromium for example uses a Release+Asserts build of Clang. This might be too much overhead for them.

That's a good idea. Do you think it is reasonable to have a blurb
about this in the LLVM Programmer’s Manual also?

LLDB for example might want to have a check like:

if (NOT LLVM_FAIL_FAST_ITERATORS STREQUAL "FORCE_OFF")
  message(FATAL_ERROR "LLDB requires a stable LLVM ABI, set LLVM_FAIL_FAST_ITERATORS to FORCE_OFF")
endif()

http://reviews.llvm.org/D8351

EMAIL PREFERENCES

http://reviews.llvm.org/settings/panel/emailpreferences/
sanjoy updated this revision to Diff 22078.Mar 17 2015, 1:19 AM
sanjoy edited edge metadata.

Address review: rename flag to LLVM_*ABI_BREAKING_CHECKS

So the current status of this change is

  • the actual code changes have already been LGTM'ed, before this

revision was uploaded

  • the autoconf changes have been LGTM'ed by Eric

Can someone please take a look at the cmake changes?

I still have to make address Reid's review of adding more
documentation, I should be able to get to it by the end of day
tomorrow.

Thanks!

  • Sanjoy
rnk accepted this revision.Mar 18 2015, 11:16 AM
rnk edited edge metadata.

cmake changes lgtm

This revision is now accepted and ready to land.Mar 18 2015, 11:16 AM

When I was looking for a place to add a small blurb documenting this
new flag, I noticed this

`--disable-assertions`

Builds LLVM with ``NDEBUG`` defined.  Changes the LLVM ABI.  Also available

in Packaging.rst.

If disabling assertions is *specified* to change the LLVM ABI then all
of this extra LLVM_ENABLE_ABI_BREAKING_CHANGES work is unneeded
complexity. If not, then should this clause be removed from
Packaging.{rst|html}?

Thanks,

  • Sanjoy
sanjoy updated this revision to Diff 22447.Mar 22 2015, 11:33 PM
sanjoy edited edge metadata.
  • Add LLVM_ENABLE_ABI_BREAKING_CHECKS to the generated config.h. I think this is a better model since this way clients do not have to remember to add -DLLVM_ENABLE_ABI_BREAKING_CHECKS when pulling in LLVM headers.
  • Add a blurb in the programmers manual.

Given that this change has received a fair amount of review already, I
plan to check the change in sometime this week in its current form
unless someone has objections or further review.

sanjoy updated this revision to Diff 22745.Mar 26 2015, 12:14 PM
  • move LLVM_ENABLE_ABI_BREAKING_CHECKS to llvm-config.h. config.h is not meant to be included in exported headers.

I'll be checking this patch in today.

This revision was automatically updated to reflect the committed changes.