HP C/aC++ for PA-RISC Software manual Runtime Checking Options, +check=all, +check=none

Page 75

Runtime Checking Options

The +check options allow you to check your application for errors at runtime.

+check

+check=allnoneboundsglobalslockmallocstackthreadtruncateuninit

The +check=xxx options provide runtime checks to detect many common coding errors in the user program. These options introduce additional instructions for runtime checks that can significantly slow down the user program. By default, a failed check will result in the program aborting at the end of execution at runtime. In most cases, an error message and a stack trace will be emitted to stderr before program termination. The environment variable RTC_NO_ABORT can be set to 0, 1, or 2 to change the behavior of failed runtime checks:

0 — A failed runtime check will abort the program immediately after the error message is emitted.

1 — The default setting, which will abort the program at the end of execution upon failure.

2 — A failed runtime check will not enable the end of execution abort.

The +check options need to be specified at both compile time and link time, since they may require additional libraries to be linked into the user program. If different +check options are specified while compiling different source files, all the specified +check options are needed at link time.

Multiple +check options are interpreted left to right. In case of conflicting options, the one on the right will override an earlier +check option.

NOTE: The +check option is only supported on Integrity servers.

+check=all

The +check=all option enables all runtime checks provided by the compiler, except for +check=truncate, +check=lock, and +check=thread, which must be explicitly specified to enable them. It overrides any +check=xxx options that appear earlier on the command line. The +check=all option is currently equivalent to the following options:

+check=bounds:array +check=globals +check=malloc +check=stack:variables +check=uninit -z

The -zoption, which is part of +check=all, can be overridden by an explicit -Zoption.

+check=none

The +check=none option turns off all runtime checking options. It disables any +check=xxxoptions that appear earlier on the command line.

+check=bounds

The +check=bounds option enables checks for out-of-bounds references to array variables or to buffers through pointer access. The check is performed for each reference to an array element or pointer access. If a check fails, an error message is emitted and the program is aborted.

The +check=bounds option applies only to local and global array variables. It also applies to references to array fields of structs. It does not apply to arrays allocated dynamically using malloc or alloca.

You can specify one of the following +check=bounds suboptions:

array - Enables check for out-of-bounds references to array variables.

pointer - Enables check for out-of-bounds references to buffers through pointer access. The buffer could be a heap object, global variable, or local variable. This suboption also checks out-of-bounds access through common libc function calls such as strcpy, strcat, memset,

Runtime Checking Options 75

Image 75
Contents HP aC++/HP C A.06.28 Programmers Guide Page Contents +FP Contents Contents Contents Data Alignment Pragmas Pragma Directives and AttributesInitialization and Termination Pragmas Copyright Notice and Identification PragmasContents Preprocessing Directives 119 Standardizing Your Code 138 Using HP aC++ Templates 132Exception Handling 161 Optimizing HP aC++ Programs 156170 Tools and Libraries 175Mixing C++ with Other Languages 188 Distributing Your C++ Products 195 Migrating from HP C++ cfront to HP aC++ 198Strings 194 Arrays Files in Fortran Glossary 223 Index 227 Documentation feedback 221 Diagnostic Messages 222HP secure development lifecycle About This Document Intended AudienceWhat’s in This Document This document uses the following conventions Typographical ConventionsHP-UX 11i Releases Publishing HistoryRelated Documents HP-UX Release Name and Release IdentifierFollowing is a list of documents available with this release HP Encourages Your CommentsOther HP aC++ executable files are Getting Started with HP aC++Components of the Compilation System C89 C99 ecom CtcomDebugging Programs Using the aCC CommandCompiling a Simple Program Executing the ProgramExamples of the aCC Command Compiler Command Syntax and Environmental VariablesPreprocessed Source Files .i Files Files on the aCC Command LineAssembly Language Source Files .s Files ++ Source File .C fileLibrary Files .a and .so Files Configuration Files .conf FilesEnvironment Variables Object Files .o FilesCclibdir Environment Variable ACCFULLPATHNAMES Environment VariableACCMAXERR Environment Variable Cxxopts Environment VariableACC -L/mnt/proj/lib file.o ACC file.o Ccrootdir Environment VariableExport CCROOTDIR=/mnt/CXX2.1 Floating InstallationCxxmapfile Environment Variable Tmpdir Environment VariableHP aC++ Setting up Floating InstallationCommand-Line Options ILP32 Data Model and LP64 Data Model Options to Control Code GenerationACC -c sub.C prog.C ACC +DO11.22 +O3 app.CCompiling in Networked Environments Using +DS to Specify Instruction SchedulingData Alignment and Storage ACC -S prog.CSize and Alignment of HP Compiler Data Types ACC +u1 app.C Debugging OptionsFshort-enums +expandtypesindiag+macrodebug When to use -g, -g0, and -g1Differences Between -g, -g0, and -g1 Options G1 AlgorithmLocal +noobjdebug+pathtrace +pathtrace=kindACC +p file.C Error HandlingNone +pathtrace=globallocal+wn +Wargs+Wcontextlimit +Wv +wperfadvice+We +Weargs+noeh Exception HandlingExtensions to the Language +wsecurity+Onofenvaccess Floating-Point Processing Options+Onocxlimitedrange +decfp FpevalFpevaldec Nofpwidetypes+Onopreservedfpregs +FPmode+Onolibmerrno +OprefetchlatencyHeader File Options ACC -I include file.C Idirs -I- -Idirs +help Online Help Option+inlinelevel num Inlining OptionsLname Library OptionsDynamic Exec+Onolibcalls= Linker OptionsMinshared +nostl+Onodynopt UsymbolUsymbol +Onodynopt+ildrelink Options for Naming the Output FileNative Language Support Option +ildACC -z file.C Handling Null Pointers OptionsCode Optimizing Options Basic Optimization Level Options+O3 +O0+O1 +O2+O4 Additional Optimization Options for Finer Control+O4 ACC +O3 prog.CIpo +nonrv+Onofailsafe +Onoptrstoglobals=list Advanced +Ooptimization Options+Onoaggressive +Onolimit+Onofltacc +Onocrossregionaddressing+Onodatalayout +Onodataprefetch+Onoinitcheck +Ofrequentlycalled+Onoinline +Olit+Ointegeroverflow +Onoopenmp +Olevel+Onolooptransform +Onoloopunroll+Onoprocelim +opts+Onoparminit +Onoparmsoverlap+Orarelycalled +Onosignedpointers+Oshortdata +Ounrollfactor +OtypesafetyProfile-Based Optimization Options +OnostoreorderingAnnotate=structs Parallel Processing OptionsInformation Embedding Options Displaying Optimization InformationRequired if -DPOSIXCSOURCEis used Option Matrix for -mt+tls=staticdynamic +Onoautopar+Ofast Performance Options+wlock Fast+DSmodel +Ofaster+Onotlscallschangetp +nosrcpos+uc Porting Options+sb +ubThis warning can be suppressed by adding an extra cast +w64bit+wdriver +wendianPreprocessor Options DnameRedirecting Output From This Option Examples Maked+Maked +makedProfiling Code Options Uname+profilebucketsize +check=none Runtime Checking Options+check +check=allCompiling with +check=boundspointer +check=boundsarray +check=boundspointerCheck off by any number out-of-bounds access Check off by one out-of-bounds access+check=lock +check=globals+check=malloc +check=thread +check=stackframevariablesnone+check=truncateimplicit +check=truncateexplicitimplicit+check=uninit Ch = intval & 0xff +check=truncateexplicitStandards Related Options AarmAarm Agcc AC89AC99 Ag++AOa and -AOe +legacycpp+legacyv5 +stl=rwnone +std=c89c99c++98c++11gccg++gnu+tru64 +tru64Wc,-ansiforscope,onoff Wc,-koeniglookup,onoffTx,name Subprocesses of the CompilerTx,name More Examples of -tWx,args Passing Options to the Linker with -W Symbol Binding OptionsBdefault BexternBprotecteddata BhiddenBhiddendef BprotectedTemplate Options +instincludesuffixes Trigraph Processing Suppression OptionVerbose Compile and Link Information Process Compiler 94/u 65/s 35/r 37/u 76/s 02/r Concatenating Options ACC -V app.CACC myfile.C -v -g1 ACC myfile.C -vg1 ACC -vg1 myfile.C Initialization and Termination Pragmas Pragma Directives and AttributesCopyright Notice and Identification Pragmas #pragma align N Data Alignment Pragmas#pragma Versionid string #pragma Versionid Software Product, Version 12345.A.01.05Data Alignment Pragmas Template Example Basic ExampleHandling Unaligned Data Implicit Access to Unaligned DataInteraction between pack and unalign pragmas is as follows #pragma unalign Typedef T1 T2Floattrapson Pragma Optimization PragmasOptlevel Pragma Optimize PragmaNoinline Pragma Other Pragmas Diagnostic PragmasExtern Pragma Defaultbinding PragmaBinding Pragma Estimatedfrequency PragmaHpdefinedinternal Pragma Hdrstop PragmaHidden Pragma Hpdefinedexternal PragmaPtrsstronglytyped Pragma POP PragmaPragma once Protected PragmaStdc Fpcontract Pragma #pragma Stdc FLOATCONSTDECIMAL64 on OFF DefaultStdc Cxlimitedrange Pragma Stdc FLOATCONSTDECIMAL64 PragmaStdc Fenvaccess Pragma Unrollfactor PragmaOMP Atomic Pragma OMP Flush Pragma OMP Barrier PragmaOMP Critical Pragma OMP for PragmaOMP Parallel for Pragma OMP Master PragmaOMP Ordered Pragma OMP Parallel PragmaOMP Task Pragma OMP Parallel Sections PragmaOMP Sections Pragma OMP Single PragmaOpenMP Clauses Copyin DefaultCopyprivate SharedAttributes Attribute noreturn Attribute nonexposingAttribute noreturn Attribute nonexposingAttribute format Attribute visibilityAttribute warnunusedresult Usage Guidelines Preprocessing DirectivesOverview of the Preprocessor SyntaxAssertions #assert, #unassert Source File Inclusion #include, #includenextSyntax DescriptionMacros with Parameters Macro Replacement #define, #undef#define mac very very long\ Replacement string ExamplesFollowing illustrates the ## operator Specifying String Literals with the # OperatorConcatenating Tokens with the ## Operator Example#define Arraysize 1000float xARRAYSIZE Using Macros to Define ConstantsOther Macros Var1 isUsing Constants and Inline Functions Instead of Macros Predefined Macros Assertions #assert, #unassertConditional Compilation #if, #ifdef, .. #endif HP aC++ predefines the following predicatesCode that compiles if the expression evaluates to zero Using the #else Directive Using the defined OperatorUsing the #if Directive Using the #ifdef and #ifndef DirectivesLine Control #line Example#line 5 myfile See page 96 for more information on pragmas This macro enables the following non-standard featuresIostream Performance Improvement Pragma Pragma Directive #pragma and Pragma OperatorLine below contains the trigraph sequence ??= Error Directive #errorTrigraph Sequences Examples??=line 5 myfile When this line is compiled it becomesTemplate Processing Using HP aC++ TemplatesInvoking Compile-Time Instantiation Scope and PrecedenceTemplate class Tablechar Explicit InstantiationUsage PerformanceACC -c +instcompiletime a.C ACC -c a.C Command-Line Option InstantiationCompile-Time Instantiation Function TemplateScope Why Use Compile-Time InstantiationPossible Duplicate Symbols in Shared Libraries Possible Duplicate Symbols in Archive LibrariesBuilding an Archive Library with Compile-time Instantiation ++ Template TutorialClass Templates Building an Archive Library with +instauto/+instcloseFunction Templates HP aC++ Keywords Standardizing Your CodeHP aC++ Keywords Bool KeywordDynamiccast Keyword Compile time error message isAbove generates a compile-time error Explicit Keyword Classic example of this problem is an array class Mutable Keyword Connections Across Translation Units Namespace and using KeywordsInt Using- declarations and using- directivesUsing Nx // Where N is a namespace, x is a name in N An Auxiliary Translation UnitPage Class Base Virtual void f Must have a virtual function to Volatile Keyword Wchart Keyword Template KeywordTypename Keyword Overloading new and delete for Arrays Use it as the name of the template C belowDeclare a class as a member of the class template C2 below Example Rangeerror Standard Exception ClassesInvalidargument Exceptions Thrown by the Standard C++ Library Typeinfo ClassFollowing exceptions are thrown by the Standard C++ Library Int before const typeinfo& const Unsupported FunctionalityMemfun1reft Memfunreft Iostream Level 1 Optimization Setting Basic Optimization LevelsOptimizing HP aC++ Programs Requesting OptimizationEnabling Aggressive Optimizations Additional Options for Finer ControlLevel 3 Optimization Level 4 OptimizationLimiting the Size of Optimized Code Removing Compilation Time Limits When OptimizingProfile-Based Optimization Enabling Only Conservative OptimizationsSample.exe input.file1 Sample.exe input.file2 InstrumentationCollecting Data for Profiling Maintaining Profile Data FilesSee Optimization Pragmas page 103 for more information Pragmas That Control OptimizationPerforming Profile-Based Optimization ACC -o sample.exe +Oprofile=use +O3 sample.CException Handling in C++ Exception HandlingFunction Try Block Examples Basic Exception Handling ExampleRogue Wave Standard C++ Library Using ThreadsUsing Locks Debugging Exception Handling Performance ConsiderationsLpthreadThis option applies only to kernel threads Required Command-line OptionsRogue Wave Standard C++ Library Rogue Wave Standard C++ Library 1.2.1 and Tools.h++Cout endl Using -DTHREADSAFE with the cfront Compatible libstreamUsing -DHPACCTHREADSAFERBTREE LimitationsPthreads Posix Threads Exception HandlingACC -mt prog.c Parallel Programming Using OpenMP Function ScopingOpenMP Implementation OpenMP Header File OpenMP LibraryOpenMP APIs are defined in the library libomp Where, kind is either of of static, dynamic, or guided +Onoopenmp Command Line OptionEnvironment Variables in OpenMP Openmp MacroExport OMPNESTED=value Setenv Ompnested value Runtime Library Functions in OpenMPExecution Environment Functions Export OMPDYNAMIC=value Setenv Ompdynamic valueOmpgetthreadnum OmpsetnumthreadsOmpgetnumthreads OmpgetmaxthreadsOmpsetnested Lock FunctionsOmpsetdynamic OmpgetdynamicOmpunsetlock and ompunsetnestlock Ompinitlock and ompinitnestlockOmpdestroylock and ompdestroynestlock Ompsetlock and ompsetnestlockOmpgetwtick Timing FunctionsOmptestlock and omptestnestlock Functions OmpgetwtimeLocale directive for lex HP Specific Features of lex and yaccCreating and Using Libraries Tools and LibrariesIntroduction Introduction to Using the Standard C++ LibraryHP aC++ Libraries Standard C++ LibraryNon-Object-Oriented Design of the Standard C++ Library Differences between Standard C++ Library and Other LibrariesIncompatibilities Between the Library and the Standard Standard C++ Library ReferenceIOStream Library ACC -DHPACCUSINGMULTIPLIESINFUNCTIONAL test.cTools.h++ Library HP aC++ Runtime Support LibrarySpecifying Other Libraries Creating and Using Shared LibrariesLinking to C++ Libraries Linking with Shared or Archive LibrariesLinking Archive or Shared Libraries Using a Shared LibraryExample of Creating and Using a Shared Library Creating a Shared LibraryAdvanced Shared Library Features Forcing the Export of Symbols in mainUpdating a Shared Library Linker Options to Manage Shared Libraries Binding TimesSide Effects of C++ Shared Libraries Routines and Options to Manage C++ Shared LibrariesAllocation Policies for Containers Standard HP-UX Libraries and Header FilesFor a string type For -AA Standard LibraryHP aC++ Executable Files HP aC++ File LocationsHP aC++ Runtime Libraries and Header Files Usr/lib/hpux##/libCsup.soUsr/lib/hpux##/libCsup11.so ISO C++11 standard compliant Mixing C++ with Other Languages Calling Other LanguagesData Compatibility between C and C++ Examples of extern C Using the extern C Linkage SpecificationHP aC++ Calling HP C Syntax of extern CDifferences in Argument Passing Conventions Main FunctionExamples HP aC++ Calling HP C HP C Calling HP aC++ Running the ExampleEnter the nameJoann Joann has a balance Compiling and Running the Sample Programs To compile the example, run the following commandsExample of Reference Variables as Arguments Using Reference Variables to Pass ArgumentsCalling HP Fortran 90 from HP aC++ Function Naming ConventionsFiles in Fortran Using extern C LinkageStrings ArraysApplications that use HP aC++ Shared Libraries Distributing Your C++ ProductsInstalling your Application Linking Your HP aC++ Libraries with Other LanguagesHP aC++ Files You May Distribute Terms for Distribution of HP aC++ Files CC +p cfrontfile.C Migrating from HP C++ cfront to HP aC++General Guidelines for Migration Getting Started with MigrationExplicit Loading and Unloading of Shared Libraries Command-Line DifferencesNew Command-Line Options Writing Code for both CompilersDescribes obsolete command-line options for HP aC++ Obsolete Command-Line OptionsPtv Changed Command-Line OptionsSee Debugging Options page 35 for complete information Migration Considerations when DebuggingMigration Considerations when Using Exception Handling Exception Handling is the DefaultMemory Allocation Failure and operator new Possible Differences when Exiting a Signal HandlerCalling unexpected Differences in setjmp/longjmp BehaviorThrowing an Object having an Ambiguous Base Class Unreachable catch ClausesStandards Based Libraries Migration Considerations when Using LibrariesMan 3s filebuf HP C++ cfront Compatibility LibrariesFstream3C++ iostream and streambuf specialized to files Manip3C++ iostream manipulatorsReplace #include with complex Migration Considerations Related to PreprocessingHP C++ cfront Complex Library Not Supported HP C++ cfront Task Library Not SupportedImplicit Typing of Character String Literals Migration Considerations Related to StandardizationObsolete Preprocessor Options Changes in C++ SemanticsExecution Order of Static Constructors in Shared Libraries Overload Resolution Ambiguity of Subscripting OperatorChanges in C++ Syntax More Frequent Inlining of Inline CodeExplicit int Declaration WC,-ansiforscope,on For Statement, New Scoping RulesStruct as Template Type Parameter is Permitted Equivalent, valid HP aC++ code followsOverload not a Keyword This code compiles without error with HP aC++Base Template Class Reference Syntax Change Tokens after #endifDangling Comma in enum Static Member Definition RequiredDeclaring friend Classes Ambiguous Function or Object Declaration Using in Class DefinitionsIncorrect Syntax for Calls to operator new Duplicate Formal Argument NamesReference Initialization Overloaded Operations ++Parentheses in Static Member Initialization List Using operator new to Allocate ArraysOn HP aC++, the following error is generated Compiling this code HP aC++ generates the following errorNon-constant Reference Initialization Qualified-id Required in Static Member Initialization ListCA a Migration Considerations when Using TemplatesVerbose Template Processing Information Digraph White Space SeparatorsConverting Directed Mode to Explicit Instantiation Common Template Migration Syntax ChangesCfront Implicit Include Convention Documentation feedback Diagnostic Messages AC++ Message CatalogFrequently Encountered Messages Aggressive GlossaryInternational Standard defines only synchronous exceptions See template Glossary Index SymbolsCrootdir FLOATTRAPSON, 103 FREQUENTLYCALLED, 106 HDRSTOP, 107 Hidden Index
Related manuals
Manual 15 pages 49.53 Kb