cling/test/NullDeref/NonNullArgCustom.C

55 lines
2.1 KiB
C++
Raw Normal View History

//------------------------------------------------------------------------------
// 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.
//------------------------------------------------------------------------------
// RUN: cat %s | %cling -Xclang -verify
// 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.
extern "C" int printf(const char* fmt, ...);
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}}
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");
}
}
// This can be a function defined in a library or somewhere else. Use printf for example
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;
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}}
.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
//trampoline()
.q