17
17
*********************************************************/
19
/*********************************************************
20
* Redistribution and use in source and binary forms, with or without
21
* modification, are permitted provided that the following conditions
24
* 1. Redistributions of source code must retain the above copyright
25
* notice, this list of conditions and the following disclaimer.
26
* 2. Redistributions in binary form must reproduce the above copyright
27
* notice, this list of conditions and the following disclaimer in the
28
* documentation and/or other materials provided with the distribution.
29
* 3. Neither the name of VMware Inc. nor the names of its contributors
30
* may be used to endorse or promote products derived from this software
31
* without specific prior written permission of VMware Inc.
33
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
34
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
35
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
36
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
37
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
38
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
39
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
40
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
41
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
42
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
45
*********************************************************/
47
/*********************************************************
48
* The contents of this file are subject to the terms of the Common
49
* Development and Distribution License (the "License") version 1.0
50
* and no later version. You may not use this file except in
51
* compliance with the License.
53
* You can obtain a copy of the License at
54
* http://www.opensource.org/licenses/cddl1.php
56
* See the License for the specific language governing permissions
57
* and limitations under the License.
59
*********************************************************/
87
129
* PR 271512: When compiling with gcc, catch assignments inside an ASSERT.
89
* 'UNLIKELY' is defined with __builtin_expect, which does not warn when passed an
90
* assignment (gcc bug 36050).
91
* To get around this, we put 'cond' in an 'if' statement and make sure it never gets
92
* executed by putting that inside of 'if (0)'.
93
* We use gcc's statement expression syntax to make ASSERT an expression because some
94
* code uses it that way.
131
* 'UNLIKELY' is defined with __builtin_expect, which does not warn when
132
* passed an assignment (gcc bug 36050). To get around this, we put 'cond'
133
* in an 'if' statement and make sure it never gets executed by putting
134
* that inside of 'if (0)'. We use gcc's statement expression syntax to
135
* make ASSERT an expression because some code uses it that way.
96
* Since statement expression syntax is a gcc extension and since it's not clear if
97
* this is a problem with other compilers, the ASSERT definition was not changed for
98
* them. Using a bare 'cond' with the ternary operator may provide a solution.
137
* Since statement expression syntax is a gcc extension and since it's
138
* not clear if this is a problem with other compilers, the ASSERT
139
* definition was not changed for them. Using a bare 'cond' with the
140
* ternary operator may provide a solution.
101
144
#define ASSERT_IFNOT(cond, panic) \
102
145
({if (UNLIKELY(!(cond))) { panic; if (0) { if (cond) { ; } } } (void)0;})