1*b0d29bc4SBrooks Davisdnl Copyright 2010 The Kyua Authors. 2*b0d29bc4SBrooks Davisdnl All rights reserved. 3*b0d29bc4SBrooks Davisdnl 4*b0d29bc4SBrooks Davisdnl Redistribution and use in source and binary forms, with or without 5*b0d29bc4SBrooks Davisdnl modification, are permitted provided that the following conditions are 6*b0d29bc4SBrooks Davisdnl met: 7*b0d29bc4SBrooks Davisdnl 8*b0d29bc4SBrooks Davisdnl * Redistributions of source code must retain the above copyright 9*b0d29bc4SBrooks Davisdnl notice, this list of conditions and the following disclaimer. 10*b0d29bc4SBrooks Davisdnl * Redistributions in binary form must reproduce the above copyright 11*b0d29bc4SBrooks Davisdnl notice, this list of conditions and the following disclaimer in the 12*b0d29bc4SBrooks Davisdnl documentation and/or other materials provided with the distribution. 13*b0d29bc4SBrooks Davisdnl * Neither the name of Google Inc. nor the names of its contributors 14*b0d29bc4SBrooks Davisdnl may be used to endorse or promote products derived from this software 15*b0d29bc4SBrooks Davisdnl without specific prior written permission. 16*b0d29bc4SBrooks Davisdnl 17*b0d29bc4SBrooks Davisdnl THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 18*b0d29bc4SBrooks Davisdnl "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 19*b0d29bc4SBrooks Davisdnl LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 20*b0d29bc4SBrooks Davisdnl A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 21*b0d29bc4SBrooks Davisdnl OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22*b0d29bc4SBrooks Davisdnl SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23*b0d29bc4SBrooks Davisdnl LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24*b0d29bc4SBrooks Davisdnl DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25*b0d29bc4SBrooks Davisdnl THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26*b0d29bc4SBrooks Davisdnl (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27*b0d29bc4SBrooks Davisdnl OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28*b0d29bc4SBrooks Davis 29*b0d29bc4SBrooks Davisdnl 30*b0d29bc4SBrooks Davisdnl KYUA_ATTRIBUTE_NORETURN 31*b0d29bc4SBrooks Davisdnl 32*b0d29bc4SBrooks Davisdnl Checks if the current compiler has a way to mark functions that do not 33*b0d29bc4SBrooks Davisdnl return and defines ATTRIBUTE_NORETURN to the appropriate string. 34*b0d29bc4SBrooks Davisdnl 35*b0d29bc4SBrooks DavisAC_DEFUN([KYUA_ATTRIBUTE_NORETURN], [ 36*b0d29bc4SBrooks Davis dnl This check is overly simple and should be fixed. For example, 37*b0d29bc4SBrooks Davis dnl Sun's cc does support the noreturn attribute but CC (the C++ 38*b0d29bc4SBrooks Davis dnl compiler) does not. And in that case, CC just raises a warning 39*b0d29bc4SBrooks Davis dnl during compilation, not an error. 40*b0d29bc4SBrooks Davis AC_CACHE_CHECK( 41*b0d29bc4SBrooks Davis [whether __attribute__((noreturn)) is supported], 42*b0d29bc4SBrooks Davis [kyua_cv_attribute_noreturn], [ 43*b0d29bc4SBrooks Davis AC_RUN_IFELSE([AC_LANG_PROGRAM([], [ 44*b0d29bc4SBrooks Davis#if ((__GNUC__ == 2 && __GNUC_MINOR__ >= 5) || __GNUC__ > 2) 45*b0d29bc4SBrooks Davis return 0; 46*b0d29bc4SBrooks Davis#else 47*b0d29bc4SBrooks Davis return 1; 48*b0d29bc4SBrooks Davis#endif 49*b0d29bc4SBrooks Davis ])], 50*b0d29bc4SBrooks Davis [kyua_cv_attribute_noreturn=yes], 51*b0d29bc4SBrooks Davis [kyua_cv_attribute_noreturn=no]) 52*b0d29bc4SBrooks Davis ]) 53*b0d29bc4SBrooks Davis if test "${kyua_cv_attribute_noreturn}" = yes; then 54*b0d29bc4SBrooks Davis attribute_value="__attribute__((noreturn))" 55*b0d29bc4SBrooks Davis else 56*b0d29bc4SBrooks Davis attribute_value="" 57*b0d29bc4SBrooks Davis fi 58*b0d29bc4SBrooks Davis AC_SUBST([ATTRIBUTE_NORETURN], [${attribute_value}]) 59*b0d29bc4SBrooks Davis]) 60*b0d29bc4SBrooks Davis 61*b0d29bc4SBrooks Davis 62*b0d29bc4SBrooks Davisdnl 63*b0d29bc4SBrooks Davisdnl KYUA_ATTRIBUTE_PURE 64*b0d29bc4SBrooks Davisdnl 65*b0d29bc4SBrooks Davisdnl Checks if the current compiler has a way to mark functions as pure. 66*b0d29bc4SBrooks Davisdnl 67*b0d29bc4SBrooks DavisAC_DEFUN([KYUA_ATTRIBUTE_PURE], [ 68*b0d29bc4SBrooks Davis AC_CACHE_CHECK( 69*b0d29bc4SBrooks Davis [whether __attribute__((__pure__)) is supported], 70*b0d29bc4SBrooks Davis [kyua_cv_attribute_pure], [ 71*b0d29bc4SBrooks Davis AC_COMPILE_IFELSE( 72*b0d29bc4SBrooks Davis [AC_LANG_PROGRAM([ 73*b0d29bc4SBrooks Davisstatic int function(int, int) __attribute__((__pure__)); 74*b0d29bc4SBrooks Davis 75*b0d29bc4SBrooks Davisstatic int 76*b0d29bc4SBrooks Davisfunction(int a, int b) 77*b0d29bc4SBrooks Davis{ 78*b0d29bc4SBrooks Davis return a + b; 79*b0d29bc4SBrooks Davis}], [ 80*b0d29bc4SBrooks Davis return function(3, 4); 81*b0d29bc4SBrooks Davis])], 82*b0d29bc4SBrooks Davis [kyua_cv_attribute_pure=yes], 83*b0d29bc4SBrooks Davis [kyua_cv_attribute_pure=no]) 84*b0d29bc4SBrooks Davis ]) 85*b0d29bc4SBrooks Davis if test "${kyua_cv_attribute_pure}" = yes; then 86*b0d29bc4SBrooks Davis attribute_value="__attribute__((__pure__))" 87*b0d29bc4SBrooks Davis else 88*b0d29bc4SBrooks Davis attribute_value="" 89*b0d29bc4SBrooks Davis fi 90*b0d29bc4SBrooks Davis AC_SUBST([ATTRIBUTE_PURE], [${attribute_value}]) 91*b0d29bc4SBrooks Davis]) 92*b0d29bc4SBrooks Davis 93*b0d29bc4SBrooks Davis 94*b0d29bc4SBrooks Davisdnl 95*b0d29bc4SBrooks Davisdnl KYUA_ATTRIBUTE_UNUSED 96*b0d29bc4SBrooks Davisdnl 97*b0d29bc4SBrooks Davisdnl Checks if the current compiler has a way to mark parameters as unused 98*b0d29bc4SBrooks Davisdnl so that the -Wunused-parameter warning can be avoided. 99*b0d29bc4SBrooks Davisdnl 100*b0d29bc4SBrooks DavisAC_DEFUN([KYUA_ATTRIBUTE_UNUSED], [ 101*b0d29bc4SBrooks Davis AC_CACHE_CHECK( 102*b0d29bc4SBrooks Davis [whether __attribute__((__unused__)) is supported], 103*b0d29bc4SBrooks Davis [kyua_cv_attribute_unused], [ 104*b0d29bc4SBrooks Davis AC_COMPILE_IFELSE( 105*b0d29bc4SBrooks Davis [AC_LANG_PROGRAM([ 106*b0d29bc4SBrooks Davisstatic void 107*b0d29bc4SBrooks Davisfunction(int a __attribute__((__unused__))) 108*b0d29bc4SBrooks Davis{ 109*b0d29bc4SBrooks Davis}], [ 110*b0d29bc4SBrooks Davis function(3); 111*b0d29bc4SBrooks Davis return 0; 112*b0d29bc4SBrooks Davis])], 113*b0d29bc4SBrooks Davis [kyua_cv_attribute_unused=yes], 114*b0d29bc4SBrooks Davis [kyua_cv_attribute_unused=no]) 115*b0d29bc4SBrooks Davis ]) 116*b0d29bc4SBrooks Davis if test "${kyua_cv_attribute_unused}" = yes; then 117*b0d29bc4SBrooks Davis attribute_value="__attribute__((__unused__))" 118*b0d29bc4SBrooks Davis else 119*b0d29bc4SBrooks Davis attribute_value="" 120*b0d29bc4SBrooks Davis fi 121*b0d29bc4SBrooks Davis AC_SUBST([ATTRIBUTE_UNUSED], [${attribute_value}]) 122*b0d29bc4SBrooks Davis]) 123