Skip to content


Subversion checkout URL

You can clone with
Download ZIP
Tree: 857acac801
Fetching contributors…

Cannot retrieve contributors at this time

435 lines (364 sloc) 11.746 kB
# Copyright (C) 2007-2011, Parrot Foundation.
=head1 NAME
config/auto/ - Warning flags probing.
Given a list of potential warnings available for a certain type of
compiler, probe to see which of those are valid for this particular version.
=over 4
package auto::warnings;
use strict;
use warnings;
use base qw(Parrot::Configure::Step);
use Parrot::Configure::Utils ();
use Parrot::BuildUtil;
=item C<_init>
Declare potential warnings for various compilers. Note that the compiler
key used here doesn't really exist in a unified way in Configure - would
be nice if it did so we could simplify our checks in runstep().
We create a data structure here that breaks out the warnings by compiler,
using this structure:
- -Warning1
- -Warning2
- -Warning3
- -Warning4
- -Warning5:
- foo.c
- bar.c
- -Warning6:
- baz.c
- frob.c
- -Warning7:
- cow.c
- pig.c
'basic' warnings are always used.
'cage' warnings are added only if --cage is specified during
Configure. This can be used to hold warnings that aren't ready to be
added to the default run yet.
'only' should be used as we add new warnings to the build, it will let
us insure that files we know are clean for a new warning stay clean.
'never' should be used when a particular file contains generated code
(e.g. imcc) and we cannot update it to conform to the standards.
'todo' functions just like never does, but it indicates that these
files are expected to eventually be free of this warning.
Note that there is no actual requirement that the 'file' be a full path
to a .c file; the file could be "PMCS" or "OPS" or some other identifier;
whatever the value, it will generate a Config entry prefixed with
C<ccwarn::>, which will probably be used via @@ expansion in a makefile.
It is tempting to put this into a config file, but having it in
perl gives us the ability to dynamically setup certain warnings based
on any criteria already discovered via Config.
Order is important - some warnings are invalid unless they are specified
after other warnings.
sub _init {
my $self = shift;
my $data = {
description => 'Detect supported compiler warnings',
result => '',
validated => [],
# begin gcc/g++
my $gcc = {};
my $gpp = {};
my $icc = {};
my @gcc_or_gpp = qw(
# gcc-only warnings that would break g++
my @gcc_basic = qw(
$gcc->{'basic'} = [ @gcc_or_gpp, @gcc_basic ];
$gpp->{'basic'} = [ @gcc_or_gpp ];
my @gcc_or_gpp_cage = qw(
my @gpp_cage = qw(
$gcc->{'cage'} = [ @gcc_or_gpp_cage ];
$gpp->{'cage'} = [ @gcc_or_gpp_cage, @gpp_cage ];
$gcc->{'todo'} = $gpp->{'todo'} = {
'-Wformat-nonliteral' => [ qw(
) ],
'-Wstrict-prototypes' => [ qw(
) ],
$gcc->{'never'} = $gpp->{'never'} = {
'-Wformat-nonliteral' => [ qw(
) ],
'-Wswitch-default' => [ qw(
) ],
'-Wcast-qual' => [ qw(
) ],
'-Wlogical-op' => [ qw(
) ],
# Warning flags docs
$icc->{'basic'} = [ qw(
# Disable some warnings and notifications that are overly noisy
'-diag-disable 271', # trailing comma is nonstandard
'-diag-disable 981', # operands are evaluated in unspecified order
'-diag-disable 1572', # floating-point equality and inequality comparisons are unreliable
'-diag-disable 2259', # non-pointer conversion from "typeA" to "typeB" may lose significant bits
$icc->{'cage'} = [
'-diag-enable sc3',
'-diag-enable sc-include',
$data->{'warnings'}{'gcc'} = $gcc;
$data->{'warnings'}{'g++'} = $gpp;
$data->{'warnings'}{'icc'} = $icc;
$data->{'warnings'}{'clang'} = $gcc;
## end gcc/g++
return $data;
sub runstep {
my ( $self, $conf ) = @_;
my $compiler = '';
if ( defined $conf->data->get('gccversion') ) {
$compiler = $conf->data->get('g++') ? 'g++' :
$conf->data->get('clang') ? 'clang' : 'gcc';
elsif ( $conf->option_or_data('cc') =~ /icc/ ) {
$compiler = 'icc';
if ($compiler eq '') {
$conf->debug("We do not (yet) probe for warnings for your compiler\n");
return 1;
if (
( $compiler eq 'gcc' or $compiler eq 'g++' ) and
( $conf->data->get('gccversion') >= 4.0 )
) {
push @{$self->{'warnings'}{$compiler}{'basic'}},
# standard warnings.
my @warnings = grep {$self->valid_warning($conf, $_)}
# --cage?
if ($conf->options->get('cage')) {
push @warnings, grep {$self->valid_warning($conf, $_)}
# -- only?
my %per_file;
if (exists $self->{'warnings'}{$compiler}{'only'}) {
my %only = %{$self->{'warnings'}{$compiler}{'only'}};
foreach my $warning (keys %only) {
next unless $self->valid_warning($conf, $warning);
foreach my $file (@{$only{$warning}}) {
$per_file{$file} = [ @warnings ] unless exists $per_file{$file};
push @{$per_file{$file}}, $warning;
foreach my $key (qw/todo never/) {
if (exists $self->{'warnings'}{$compiler}{$key}) {
my %dont = %{$self->{'warnings'}{$compiler}{$key}};
foreach my $warning (keys %dont) {
foreach my $file (@{$dont{$warning}}) {
$per_file{$file} = [ @warnings ] unless exists $per_file{$file};
@{$per_file{$file}} = grep {$warning ne $_} @{$per_file{$file}};
$conf->data->set('ccwarn', join(' ', @warnings));
foreach my $file (keys %per_file) {
$conf->data->set("ccwarn::$file", join(' ', @{$per_file{$file}}));
return 1;
=item C<valid_warning>
Try a given warning to see if it is supported by the compiler. The compiler
is determined by the C<cc> value of the C<Parrot::Configure> object passed
in as the first argument to the method (not counting C<$self>. The warning
to be checked is passed in as the second argument to the method.
Returns true if the warning flag is recognized by the compiler and undef
Use the running set of known valid options, since some options may depend
on previous options.
sub valid_warning {
my ( $self, $conf, $warning ) = @_;
# This should be using a temp file name.
my $output_file = 'test.cco';
$conf->debug("trying attribute '$warning'\n");
my $cc = $conf->option_or_data('cc');
my $ccflags = $conf->data->get('ccflags');
my $warnings = join(' ', @{$self->{'validated'}});
my $tryflags = "$ccflags $warnings $warning";
my $command_line = Parrot::Configure::Utils::_build_compile_command( $cc, $tryflags );
$conf->debug(" ", $command_line, "\n");
# Don't use cc_build, because failure is expected.
my $exit_code = Parrot::Configure::Utils::_run_command(
$command_line, $output_file, $output_file
# Cleanup any remnants of the test compilation
if ($exit_code) {
unlink $output_file or die "Unable to unlink $output_file: $!";
my $output = Parrot::BuildUtil::slurp_file($output_file);
unlink $output_file or die "Unable to unlink $output_file: $!";
$conf->debug(" output: $output\n");
if ( $output !~ /\berror|warning|not supported|ignoring (unknown )?option\b/i ) {
push @{$self->{'validated'}}, $warning;
$conf->debug(" valid warning: '$warning'\n");
return 1;
else {
$conf->debug(" invalid warning: '$warning'\n");
return 0;
# Local Variables:
# mode: cperl
# cperl-indent-level: 4
# fill-column: 100
# End:
# vim: expandtab shiftwidth=4:
Jump to Line
Something went wrong with that request. Please try again.