-qcheck
Category
Purpose
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 might result in slower application execution.
Syntax
.-nocheck------------------------------. >>- -q--+-check--+---------------------------+-+--------------->< | .-:------------------. | | V .-all------------. | | '-=----+-bounds---------+-+-' +-nobounds-------+ +-divzero--------+ +-nodivzero------+ +-nullptr--------+ +-nonullptr------+ +-stackclobber---+ +-nostackclobber-+ +-unset----------+ '-nounset--------'
Defaults
-qnocheck
Parameters
- all
- Enables all suboptions.
- bounds | nobounds
- Performs runtime checking of addresses for subscripting within
an object of known size. The index is checked to ensure that it will
result in an address that lies within the bounds of the object's storage.
A trap will occur if the address does not lie within the bounds of
the object.
This suboption has no effect on accesses to a variable length array.
- divzero | nodivzero
- Performs runtime checking of integer division. A trap will occur if an attempt is made to divide by zero.
- nullptr | nonullptr
- Performs runtime checking of addresses contained in pointer variables used to reference storage. The address is checked at the point of use; a trap will occur if the value is less than 512.
- stackclobber | nostackclobber
- Detects stack corruption of nonvolatile registers in the save area in user programs. This type of corruption happens only if any of the nonvolatile registers in the save area of the stack is modified.
- unset | nounset
- Checks for automatic variables that are used before they are set.
A trap will occur at run time if an automatic variable is not set
before it is used.
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.
Usage
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. Predefined macros
None.
Examples
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.