2014-01-07 14:57:02 +04:00
//------------------------------------------------------------------------------
// CLING - the C++ LLVM-based InterpreterG :)
//
// This file is dual-licensed: you can choose to license it under the University
// of Illinois Open Source License or the GNU Lesser General Public License. See
// LICENSE.TXT for details.
//------------------------------------------------------------------------------
2013-09-09 17:32:53 +04:00
// RUN: cat %s | %cling -Xclang -verify
2013-08-16 00:20:55 +04:00
// We must be able to handle cases where, there is a custom function that has
// attributes non-null arguments and we should be able to add a non-null arg
// attribute to a say library function.
// Qualified functions.
2013-08-21 13:29:28 +04:00
extern " C " int printf ( const char * fmt , . . . ) ;
2013-08-16 00:20:55 +04:00
namespace custom_namespace {
2014-02-18 11:22:16 +04:00
void standaloneFunc ( void * p , int q , float * s ) __attribute__ ( ( nonnull ( 1 , 3 ) ) ) { // expected-warning {{GCC does not allow 'nonnull' attribute in this position on a function definition}}
2013-08-16 00:20:55 +04:00
if ( ! p | | ! s )
printf ( " Must not be called with 0 args. \n " ) ;
}
void standaloneFunc2 ( void * p , int q , float * s ) __attribute__ ( ( nonnull ( 3 ) ) ) ;
void standaloneFunc2 ( void * p , int q , float * s ) {
if ( ! s )
printf ( " Must not be called with 0 args. \n " ) ;
}
}
2013-08-21 13:29:28 +04:00
// This can be a function defined in a library or somewhere else. Use printf for example
2013-08-16 00:20:55 +04:00
extern " C " int printf ( const char * fmt , . . . ) __attribute__ ( ( nonnull ( 1 ) ) ) ;
int * pNull = 0 ;
float * fNull = 0 ;
int * p = new int ( 1 ) ;
float * f = new float ( 0.0 ) ;
const char * charNull = 0 ;
2013-09-09 17:32:53 +04:00
custom_namespace : : standaloneFunc ( pNull , 1 , fNull ) ; // expected-warning {{null passed to a callee which requires a non-null argument}}
custom_namespace : : standaloneFunc ( pNull , 1 , f ) ; // expected-warning {{null passed to a callee which requires a non-null argument}}
custom_namespace : : standaloneFunc ( p , 1 , fNull ) ; // expected-warning {{null passed to a callee which requires a non-null argument}}
printf ( charNull , " " ) ; // expected-warning {{null passed to a callee which requires a non-null argument}}
2013-08-16 00:20:55 +04:00
. rawInput 1
int trampoline ( ) {
custom_namespace : : standaloneFunc ( pNull , 1 , fNull ) ;
custom_namespace : : standaloneFunc ( pNull , 1 , f ) ;
custom_namespace : : standaloneFunc ( p , 1 , fNull ) ;
return 1 ;
}
. rawInput 0
2013-09-09 17:32:53 +04:00
//trampoline()
2013-08-16 00:20:55 +04:00
. q