Sponsored Content
Top Forums Programming -Warray-bounds option to GCC compiler Post 303013371 by milhan on Tuesday 20th of February 2018 11:55:09 AM
Old 02-20-2018
Quote:
Originally Posted by hicksd8
What level of optimization are you using?

Try at least level -O2 and it will probably catch it. Without at least that level the compiler doesn't do enough work to detect out-of-bounds but it should still detect it at run-time.
Hi,
I turned on -O2 on linux fedora (g++ GCC 7.3.1 20180130 Red Hat 7.3.1-2) and also tried the same code on a FreeBSD unix (g++ FreeBSD Ports Collection 6.4.0) and they both didn't catch the array out-of-bounds when both -O2 and -Warray-bounds=2 are enabled.
Code:
~ alias g++                                                                                                                                                              
alias g++='g++ -O2 -Wall -Wextra -Wchkp -Wmissing-include-dirs -Wswitch-default -Wunused \
  -Wduplicated-branches -Wduplicated-cond -Wshadow -Wpointer-arith -Wundef -Wunused-macros \
  -Wcast-qual -Wzero-as-null-pointer-constant -Wparentheses -Wuseless-cast -Wsign-conversion \
  -Wlogical-op -Wredundant-decls -Wrestrict -Winvalid-pch -Warray-bounds=2'
~ g++ t2.cpp && a.out 
999

 

9 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

cc compiler / gcc

:confused: I have a question concerning gcc. IŽd like to install the gcc on my Mac OS X, but when I try to run the configure command I get the following message: floriant% ./configure ./configure: read-only variable: PWD Configuring for a powerpc-apple-darwin5.4 host. *** This configuration... (2 Replies)
Discussion started by: florian.turck
2 Replies

2. Programming

gcc compiler

i write c++ code it run perfectely with g++ compiler but same code when i compile with GCC compiler it gives linker error , followed these linker error /tmp/ccfZtXOQ.o(.text+0x22): In function `main': conf_system.cpp: undefined reference to `operator new(unsigned int)'... (5 Replies)
Discussion started by: munnu
5 Replies

3. UNIX for Dummies Questions & Answers

xl C/C++ compiler to GCC compiler

Hi, we are converting from IBM-AIX(xl c/c++ compiler) to Linux(GCC complier). As a part of this i need to change the CFLAGS. The xl c/c++ complier CFLAGS is CFLAGS := $(CDEBUG) $(PROJECT_INCLUDE_DIRS) $(COBJECT_MODE) -qcpluscmt -qmakedep -qcheck=all \ -qalign=bit_packed $(LINT_FLAGS)... (0 Replies)
Discussion started by: pbattu1
0 Replies

4. AIX

AIX 5.3 gcc compiler

Hi there I've got a problem getting my mysql libraries to work. every time I compile my source code it gives my a compiler error. Cannot find a rule to create target /usr/include/mysql/mysql.h AND /usr/include/mysql/mysql.h: Permission denied Is anyone fimiliar with this error, and can... (1 Reply)
Discussion started by: cipher#1
1 Replies

5. Ubuntu

gcc compiler

where to download gcc compiler for ubuntu? how to install? how to build and run "c programs"? screen shots if possible.....:b::D tutorials too:cool: (5 Replies)
Discussion started by: villanarun
5 Replies

6. Shell Programming and Scripting

gcc compiler

I am using open suse linux. I want to install gcc compiler in my machine. I ahve checked man gcc and man cc. But it's not there. Can someone help me (4 Replies)
Discussion started by: pritish.sas
4 Replies

7. Programming

gcc compiler

Which gcc compiler release had the Arm 9 multicore support?Whether the compiler that used for the single Arm 9 core can be used for its multicore systems ? If gcc not support,please tell me which are the compilers that are available for Arm 9 multicore systems (including commerical).Whether... (0 Replies)
Discussion started by: sujith4u87
0 Replies

8. UNIX for Dummies Questions & Answers

cc compiler and gcc compiler

hi, can we install gcc compiler in unix based OS(sun solar,IBM AIX,HP,etc) and also can we install sun cc compiler in AIX environment and vice versa. and more ..is linux support cc compiler regards Ajay (3 Replies)
Discussion started by: ajaysahoo
3 Replies

9. Programming

A question regarding the gcc compiler ...

It might be a simple one but I have this question bothering me for sometime. When we do a symbol search inside the library directory (i.e. /usr/lib/*) via tools like nm; it takes a while to give us the results. However, its very quick when gcc is invoked to compile a program with the very same... (11 Replies)
Discussion started by: Praveen_218
11 Replies
ExtUtils::XSpp::Exception(3pm)				User Contributed Perl Documentation			    ExtUtils::XSpp::Exception(3pm)

NAME
ExtUtils::XSpp::Exception - Map C++ exceptions to Perl exceptions DESCRIPTION
This class is both the base class for the different exception handling mechanisms and the container for the global set of exception mappings from C++ exceptions (indicated by a C++ data type to catch) to Perl exceptions. The Perl exceptions are implemented via "croak()". The basic idea is that you can declare the C++ exception types that you want to handle and how you plan to do so by using the %exception directive in your XS++ (or better yet, in the XS++ typemap): // OutOfBoundsException would have been declared // elsewhere as: // // class OutOfBoundsException : public std::exception { // public: // OutOfBoundsException() {} // virtual const char* what() const throw() { // return "You accessed me out of bounds, fool!"; // } // } %exception{outOfBounds}{OutOfBoundsException}{stdmessage}; If you know a function or method may throw "MyOutOfBoundsException"s, you can annotate the declaration in your XS++ as follows: double get_from_array(unsigned int index) %catch{outOfBounds}; When "get_from_array" now throws an "OutOfBoundsException", the user gets a Perl croak with the message "Caught exception of type 'OutOfBoundsException': You accessed me out of bounds, fool!". There may be any number of %catch directives per method. Note: Why do we assign another name ("outOfBounds") to the existing "OutOfBoundsException"? Because you may need to catch exceptions of the same C++ type with different handlers for different methods. You can, in principle, re-use the C++ exception class name for the exception map name, but that may be confusing to posterity. Instead of adding %catch to methods, you may also specify exceptions that you wish to handle for all methods of a class: class Foo %catch{SomeException,AnotherException} { ... }; The %catch{Foo,Bar,...} syntax is shorthand for "%catch{Foo} %catch{Bar} ...". If there are exceptions to be caught both from the class and attached to a method directly, the exceptions that are attached to the method only will be handled first. No single type of exceptions will be handled more than once, therefore it is safe to use this precedence to re-order the class-global exception handling for a single method. If there are no %catch decorators on a method, exceptions derived from "std::exception" will be caught with a generic "stdmessage" handler such as above. Even if there are %catch clauses for the given method, all otherwise uncaught exceptions will be caught with a generic error message for safety. Exception handlers There are different cases of Perl exceptions that are implemented as sub-classes of "ExtUtils::XSpp::Exception": ExtUtils::XSpp::Exception::simple implements the most general case of simply throwing a generic error message that includes the name of the C++ exception type. ExtUtils::XSpp::Exception::stdmessage handles C++ exceptions that are derived from "std::exception" and which provide a "char* what()" method that will provide an error message. The Perl-level error message will include the C++ exception type name and the exception's "what()" message. ExtUtils::XSpp::Exception::code allows the user to supply custom C/C++/XS code that will be included in the exception handler verbatim. The code has access to the exception object as the variable "e". Your user supplied code is expected to propagate the exception to Perl by calling croak(). ExtUtils::XSpp::Exception::object maps C++ exceptions to throwing an instance of some Perl exception class. Syntax: %exception{myClassyException}{CppException}{object}{PerlClass}; Currently, this means just calling "PerlClass->new()" and then die()ing with that object in $@. There is no good way to pass information from the C++ exception object to the Perl object. Will change in future. ExtUtils::XSpp::Exception::unknown is the default exception handler that is added to the list of handlers automatically during code generation. It simply throws an entirely unspecific error and catches the type "..." (meaning anything). There is a special exception handler "nothing" which is always available: int foo() %catch{nothing}; It indicates that the given method (or function) is to handle no exceptions. It squishes any exception handlers that might otherwise be inherited from the method's class. METHODS
new Creates a new "ExtUtils::XSpp::Exception". Calls the "$self->init(@_)" method after construction. "init()" must be overridden in subclasses. handler_code Unimplemented in this base class, but must be implemented in all actual exception classes. Generates the "catch(){}" block of code for inclusion in the XS output. First (optional) argument is an integer indicating the number of spaces to use for the first indentation level. indent_code Given a piece of code and a number of spaces to use for global indentation, indents the code and returns it. cpp_type Fetches the C++ type of the exception from the "type" attribute and returns it. ACCESSORS
name Returns the name of the exception. This is the "myException" in %exception{myException}{char*}{handler}. type Returns the ExtUtils::XSpp::Node::Type C++ type that is used for this exception. This is the "char*" in %exception{myException}{char*}{handler}. CLASS METHODS
add_exception Given an "ExtUtils::XSpp::Exception" object, adds this object to the global registry, potentially overwriting an exception map of the same name that was in effect before. get_exception_for_name Given the XS++ name of the exception map, fetches the corresponding "ExtUtils::XSpp::Exception" object from the global registry and returns it. Croaks on error. perl v5.14.2 2011-12-20 ExtUtils::XSpp::Exception(3pm)
All times are GMT -4. The time now is 01:03 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy