Skip to content

C/C++ frontends: select standard using the same rules as the compiler we emulate #2364

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

smowton
Copy link
Contributor

@smowton smowton commented Jun 19, 2018

Both GCC and Clang have changed the C and C++ standards they pick by default when no -std argument is passed. Since the preprocessor is invoked also with no -std either, it may define e.g. __cplusplus or __STDC_VERSION__ in a way that causes standard library includes to use C++14 or C11 features -- in this case goto-cc needs to expect that and parse them correctly.

This PR also amends our Travis config to symlink the compiler we build with as $HOME/bin/gcc and $HOME/bin/g++ (even if it's really Clang, since Clang-named-gcc is common e.g. on OSX), so that our goto-cc tests find this version as their underlying compiler (the one it uses for preprocessing). Previously goto-cc C tests were using gcc-5 (even when built with Clang) but C++ tests were using g++-4.8, the system default on Ubuntu 14.04.

Finally I add builds using gcc-8 and clang-6 (the latest version of each compiler). I can add complete testing for GCC {5, 6, 7, 8} and Clang {3.7, 3.8, 3.9, 4, 5, 6}, but I figured that might run up too large of a bill.

@smowton smowton force-pushed the smowton/fix/autodetect-default-cxx-dialect branch from 7963d06 to 0bbf879 Compare June 19, 2018 12:15
@smowton
Copy link
Contributor Author

smowton commented Jun 19, 2018

For some reason had to push this as a branch on diffblue/cbmc to get any Travis build running

@smowton smowton force-pushed the smowton/fix/autodetect-default-cxx-dialect branch from 0bbf879 to 6dd0d8a Compare June 19, 2018 14:05
@kroening
Copy link
Member

May I suggest to split out the extra Travis jobs? I have been restarting Travis jobs all day, and doubt that Travis can handle this.

@smowton
Copy link
Contributor Author

smowton commented Jun 19, 2018

Can do in general, but I will leave them in this PR as this change specifically needs CI'ing against gcc-7 and clang-6. Then I'll remove them before merge.

We should move to AWS CodeBuild if Travis can't take this. I read a bit about how we should set this up and messaged @forejtv.

@smowton smowton force-pushed the smowton/fix/autodetect-default-cxx-dialect branch from 6dd0d8a to ef41673 Compare June 19, 2018 16:10
@smowton
Copy link
Contributor Author

smowton commented Jun 19, 2018

Rewrote this to extract default language standard at the same time as querying version. Regrettably this means a second run to get __cplusplus, which will never be defined at the same time as __STDC_VERSION__. Please re-review.

The old idea (derive default standard from compiler version) was undone by Apple claiming Clang 8.1.0, but it is derived from LLVM 3.9.0 and uses default C++98. I could special case that as well... but something somewhere would lie in a different way, so I though it better to ask the actual question I intend, "what language standard do you think you're compiling?"

smowton added 2 commits June 19, 2018 17:22
…iler

This ensures that goto-cc with no `-std` explicitly specified will expect the same
language standard as the underlying compiler's preprocessor -- so for example, using
`goto-cc test.cpp`, which invokes `g++-7 -E` to perform preprocessing, will be able to
parse the C++14 constructs in the standard library exposed because g++-6 and above
enable C++14 support by default.
These were previously broken on g++-6 and above, as the compiler defaults to C++14 mode.
@smowton smowton force-pushed the smowton/fix/autodetect-default-cxx-dialect branch from ef41673 to 19de946 Compare June 19, 2018 16:22
@kroening
Copy link
Member

I like the new way better, as it relieves us from tracking the default of the various compilers.
Still doubt that Travis can deliver what you expect it to do.

@smowton
Copy link
Contributor Author

smowton commented Jun 19, 2018

The build / test matrix here btw is:

Gcc-5 tested with gcc-5
Gcc-7 tested with gcc-7
Clang-3.7 tested with gcc-5
Clang-6.0 tested with gcc-5
Apple clang 8.1.0 tested with self

The non-Apple Clangs are not running tests using the same compiler because they fail tests at the moment. Gcc-8 is not tested as cbmc doesn't build due to a bad catch-by-value (PR coming up) and small_map breaking rules for use of memmove (contacted Dan Poetzel about this)

@smowton smowton force-pushed the smowton/fix/autodetect-default-cxx-dialect branch from 19de946 to 4491b4a Compare June 20, 2018 08:15
Copy link
Contributor

@allredj allredj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Passed Diffblue compatibility checks (cbmc commit: 4491b4a).
Build URL: https://travis-ci.com/diffblue/test-gen/builds/76783517

@smowton
Copy link
Contributor Author

smowton commented Jun 20, 2018

@kroening looks like this is working now. Travis is coping -- of course this raises the number of Travis jobs in the second stage from 6 to 8. @tautschnig @peterschrammel please review

Copy link
Collaborator

@tautschnig tautschnig left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me - just minor notes.

- libc6-dev-i386
before_install:
- mkdir bin
# Use gcc/g++ 5 for tests, as Clang doesn't work yet
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is it that's going wrong - could you be more verbose about this, please?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please include a reference to #2370 in the comment? (Though we should of course really fix #2370...)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Already done, rotate your eyeballs down one line ;)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Somehow GitHub should get smarter about this. (Surely it can't be me who is lacking the smarts :-P)

@@ -41,7 +41,7 @@ IREP_ID_ONE(member_name)
IREP_ID_TWO(C_member_name, #member_name)
IREP_ID_TWO(equal, =)
IREP_ID_TWO(implies, =>)
IREP_ID_TWO(iff, <=>)
IREP_ID_TWO(iff, "<=>")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See #1974 - I'd say the commit message should include a pointer to that issue.

smowton added 2 commits June 20, 2018 11:39
Also use the build compiler, not the system default, for tests. This was already done
with gcc (by placing a symlink named 'gcc' pointing to gcc-5 in a directory ahead of /usr/bin
in the path), but g++ tests were using the image default compiler -- g++-4.8 for Ubuntu Trusty.
clang++-6.0 warns that in the next C++ standard <=> will be an operator and therefore an atomic
lexical token. I think that's overly zealous, but it's easily worked around by explicitly quoting
the name, which will be stringified before use in any case.

See diffblue#1974 for more details, or
https://bugs.llvm.org/show_bug.cgi?id=36925 for an upstream bug report.
@smowton smowton force-pushed the smowton/fix/autodetect-default-cxx-dialect branch from 4491b4a to 7210136 Compare June 20, 2018 10:39
@smowton
Copy link
Contributor Author

smowton commented Jun 20, 2018

@tautschnig done, see #2370 for specific failures when the native compiler is Clang

@kroening kroening merged commit f5f32da into diffblue:develop Jun 20, 2018
Copy link
Contributor

@allredj allredj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Passed Diffblue compatibility checks (cbmc commit: 7210136).
Build URL: https://travis-ci.com/diffblue/test-gen/builds/76800670

NathanJPhillips pushed a commit to NathanJPhillips/cbmc that referenced this pull request Aug 22, 2018
8a7893c Merge pull request diffblue#2375 from diffblue/unit-dependencies
9258284 fix build depenencies of unit test binary
f7cd161 Merge pull request diffblue#2371 from diffblue/fix-tests2
82753bc make test independent of index type
f5f32da Merge pull request diffblue#2364 from smowton/smowton/fix/autodetect-default-cxx-dialect
d437f60 Merge pull request diffblue#2368 from polgreen/doc_replace_func_bodies
6048517 Merge pull request diffblue#2353 from tautschnig/g++8-fixes2
e2e6d82 Merge pull request diffblue#2190 from tautschnig/more-stats
7210136 Make it clearer that <=> will always be stringified
560f82b Travis: test more g++ and clang versions
d46a55c Add new goto-instrument option print-global-state-size
961b29a Silence GCC 8's warning about using realloc/memmove on non-POD
ca1b03c Documentation wording for replace function bodies
d8c5a98 Cleanup options handling of count-eloc, list-eloc, print-path-lengths
6cd6d31 Unit test framwork: use references when catching exceptions
6882da6 Merge pull request diffblue#2367 from diffblue/fix-tests
bcc3bef make regression/cbmc/bounds_check1 independent of types used
4de4538 switch regression/cbmc/Typecast2 to preprocessed code
91a9c64 Amend two tests that explicitly target C++98
2b2b797 goto-gcc: select default language standard depending on emulated compiler
52a8afc Merge pull request diffblue#1898 from tautschnig/always-inline
cbe691b Merge pull request diffblue#2363 from diffblue/Makefile-TAR
9d40a9e Merge pull request diffblue#2365 from diffblue/solaris_errno
9efd705 add model for ___errno for Solaris 11
eaa2e05 update Solaris instructions
2f142d5 allow customizing the tar command for solver download
8cc1848 Merge pull request diffblue#1860 from tautschnig/restore-irept-sharing
fea5db0 Merge pull request diffblue#2361 from diffblue/fix-goto2
7c0d750 Merge pull request diffblue#2362 from smowton/smowton/fix/tolerate-cxx-namespace-attribute
e440a25 introduce INCOMPLETE_GOTO and turn guarded goto into a stateless pass
1f1835b C++ frontend: tolerate namespace attributes
cbce4bc Unit test of irept's public API
abdb044 Unit test to check that irept implements sharing
d58fd18 Silence the linter on assert in irep.h
3d64070 Partially revert "Use small intrusive pointer in irep"
688a0ab Macros are not needed outside translation units
9c93f59 Fully interpret __attribute__((always_inline))
d1f617b Apply symbol replacement in type_arg members

git-subtree-dir: cbmc
git-subtree-split: 8a7893c
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants