#pragma options [no]check
Generates code that performs certain types of runtime checking.
If a violation is encountered, a runtime error is raised by sending a SIGTRAP signal to the process. Note that the runtime checks may result in slower application execution.
.-nocheck------------------------------. >>- -q--+-check--+---------------------------+-+--------------->< | .-:------------------. | | V .-all------------. | | '-=----+-bounds---------+-+-' +-nobounds-------+ +-divzero--------+ +-nodivzero------+ +-nullptr--------+ +-nonullptr------+ +-stackclobber---+ +-nostackclobber-+ +-unset----------+ '-nounset--------'
-qnocheck
This suboption has no effect on accesses to a variable length array.
If the -qstackprotect option and this suboption are both on, this suboption detects the stack corruption first.
The -qinitauto option initializes automatic variables. As a result, the -qinitauto option hides uninitialized variables from the -qcheck=unset option.
Specifying the -qcheck option with no suboptions is equivalent to specifying -qcheck=all.
You can specify the -qcheck option more than once. The suboption settings are accumulated, but the later suboptions override the earlier ones.
xlc myprogram.c -qcheck=all:nonullptr
provides
checking for everything except for addresses contained in pointer
variables used to reference storage. If you use all with the no... form
of the suboptions, all should be the first suboption. None.
void func1(int* p) {
*p = 42; /* Traps if p is a null pointer */
}
void func2(int i) {
int array[10];
array[i] = 42; /* Traps if i is outside range 0 - 9 */
}
void func3(int a, int b) {
a / b; /* Traps if b=0 */
}
The following code example shows the effect of -qcheck=stackclobber:
void func4(char *p, int off, int value) {
*(p+off)=value;
}
int foo() {
int i;
char boo[9];
i=24;
func4(boo, i, 66);
/* Traps here */
return 0;
}
int main() {
foo();
}
xlc -g -O -qcheck=unset factorial.c
factorial.c contains
the following code:int factorial(int n) {
int result;
if (n > 1) {
result = n * factorial(n - 1);
}
return result; /* line 8 */
}
int main() {
int x = factorial(1);
return x;
}
The compiler issues the following informational message
during compile time and a trap occurs at line 8 during run time:1500-099: (I) "factorial.c", line 8: "result" might be used before it is set.