Skip to content

Commit 4fa3ba5

Browse files
committed
Create separate clang build with NDEBUG and CPROVER_INVARIANT_DO_NOT_CHECK
Fix INVARIANT macros for CPROVER_INVARIANT_DO_NOT_CHECK and CPROVER_INVARIANT_ASSERT In NDEBUG build, disable known warnings caused by the disabled versions of the INVARIANT macros.
1 parent ee4a887 commit 4fa3ba5

File tree

2 files changed

+34
-4
lines changed

2 files changed

+34
-4
lines changed

.travis.yml

+27
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,33 @@ jobs:
165165
- EXTRA_CXXFLAGS="-DDEBUG"
166166
script: echo "Not running any tests for a debug build."
167167

168+
# Ubuntu Linux with glibc using clang++-3.7, no-debug mode
169+
- stage: Test different OS/CXX/Flags
170+
os: linux
171+
sudo: false
172+
compiler: clang
173+
cache: ccache
174+
addons:
175+
apt:
176+
sources:
177+
- ubuntu-toolchain-r-test
178+
- llvm-toolchain-precise-3.7
179+
packages:
180+
- libwww-perl
181+
- clang-3.7
182+
- libstdc++-5-dev
183+
- libubsan0
184+
before_install:
185+
- mkdir bin ; ln -s /usr/bin/clang-3.7 bin/gcc
186+
- export CCACHE_CPP2=yes
187+
env:
188+
- COMPILER="ccache clang++-3.7 -Qunused-arguments -fcolor-diagnostics"
189+
- CCACHE_CPP2=yes
190+
# Disable known warnings caused by -DCPROVER_INVARIANT_DO_NOT_CHECK.
191+
- EXTRA_CXXFLAGS="-DNDEBUG -DCPROVER_INVARIANT_DO_NOT_CHECK -Wno-return-type -Wno-unused-variable -Wno-sometimes-uninitialized -Wno-unused-function"
192+
script: echo "Not running any tests for a debug build."
193+
194+
# cmake build using g++-5
168195
- stage: Test different OS/CXX/Flags
169196
os: linux
170197
cache: ccache

src/util/invariant.h

+7-4
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,6 @@ class invariant_failedt: public std::logic_error
8383
const std::string &reason);
8484

8585
public:
86-
8786
const std::string file;
8887
const std::string function;
8988
const int line;
@@ -117,20 +116,24 @@ class invariant_failedt: public std::logic_error
117116
#define INVARIANT(CONDITION, REASON) \
118117
__CPROVER_assert((CONDITION), "Invariant : " REASON)
119118

119+
#define INVARIANT_STRUCTURED(CONDITION, TYPENAME, ...) \
120+
INVARIANT(CONDITION, "")
120121

121122
#elif defined(CPROVER_INVARIANT_DO_NOT_CHECK)
122123
// For performance builds, invariants can be ignored
123124
// This is *not* recommended as it can result in unpredictable behaviour
124125
// including silently reporting incorrect results.
125126
// This is also useful for checking side-effect freedom.
126-
#define INVARIANT(CONDITION, REASON, ...) do {} while(0)
127+
#define INVARIANT(CONDITION, REASON) do {} while(0)
128+
#define INVARIANT_STRUCTURED(CONDITION, TYPENAME, ...) do {} while(0)
127129

128130
#elif defined(CPROVER_INVARIANT_ASSERT)
129131
// Not recommended but provided for backwards compatability
130132
#include <cassert>
131133
// NOLINTNEXTLINE(*)
132-
#define INVARIANT(CONDITION, REASON, ...) assert((CONDITION) && ((REASON), true))
133-
134+
#define INVARIANT(CONDITION, REASON) assert((CONDITION) && ((REASON), true))
135+
// NOLINTNEXTLINE(*)
136+
#define INVARIANT_STRUCTURED(CONDITION, TYPENAME, ...) assert((CONDITION))
134137
#else
135138

136139
void print_backtrace(std::ostream &out);

0 commit comments

Comments
 (0)