gcc / clang: -fmax-errors / -ferror-limit: why the triggering condition is "exceeded" rather than "reached"? - gcc

Sample code (t999.c):
int_ x;
Incvocatoins:
$ gcc t999.c -fmax-errors=1
t999.c:1:1: error: unknown type name ‘int_’; did you mean ‘int’?
1 | int_ x;
| ^~~~
| int
$ clang t999.c -ferror-limit=1
t999.c:1:1: error: unknown type name 'int_'; did you mean 'int'?
int_ x;
^~~~
int
1 error generated.
Here we see that:
gcc have not generated compilation terminated due to -fmax-errors=1.
clang have not generated fatal error: too many errors emitted, stopping now [-ferror-limit=].
Conclusion: in both gcc and clang the triggering condition is "exceeded" rather than "reached".
Descriptions:
-fmax-errors=n
Limits the maximum number of error messages to n, at which point GCC
bails out rather than attempting to continue processing the source
code.
-ferror-limit=123
Stop emitting diagnostics after 123 errors have been produced.
Questions:
Why the triggering condition is "exceeded" rather than "reached"?
Should the triggering condition be "reached" rather than "exceeded"?
(extra) Does the current behavior ("exceeded" rather than "reached") correspond to the descriptions above?

Related

How to query GCC warnings for C++?

GCC allows querying available warning flags specific for C++ language with the syntax:
g++ -Q --help=warning,c++
Adding warning flags to the call includes them in the result:
g++ -Wall -Q --help=warning,c++
However, it seems the call is done from the C point of view and I don't know how to do it from the C++ point of view. If the call includes C++-only warning, like:
g++ -Wnon-virtual-dtor -Q --help=warning,c++
the output contains a message:
cc1: warning: command line option ‘-Wnon-virtual-dtor’ is valid for C++/ObjC++ but not for C
and still shows the warning as disabled:
-Wnon-virtual-dtor [disabled]
Note, that this happens regardless of whether the call is done using g++ or gcc.
The same with C-only -Wbad-function-cast behaves in an expected way:
gcc -Wbad-function-cast -Q --help=warning,c
There is no extra message and reported warning status changes between [disabled] and [enabled]. Again, regardless of whether g++ or gcc is used.
I'm using GCC version 7.3.0. Although the issue seems to apply to many if not all versions. It can be observed through Compiler Explorer.
So, is there a way to do this query with respect to given language?
Yes, your observations are correct.
Probably this is not the intended behavior, and if you care about this feature, then I suggest reporting it upstream.
Note that this works, however:
touch 1.cc
g++ -Wnon-virtual-dtor -Q --help=warning,c++ 1.cc
I.e. if there's an input file with a proper extension, then the correct compiler proper executable is invoked: cc1plus, not cc1. The latter is the default if no input files are present. I did some quick debugging, and here's how that happens:
// gcc.c:
driver::do_spec_on_infiles () const
{
...
for (i = 0; (int) i < n_infiles; i++)
{
...
/* Figure out which compiler from the file's suffix. */
input_file_compiler
= lookup_compiler (infiles[i].name, input_filename_length,
infiles[i].language);
if (input_file_compiler)
{
...
value = do_spec (input_file_compiler->spec);
And input_file_compiler at that point is the C compiler, because
p n_infiles
$9 = 1
(gdb) p infiles[0]
$10 = {name = 0x4cbfb0 "help-dummy", language = 0x4cbfae "c", incompiler = 0x58a920, compiled = false, preprocessed = false}
Here's how the dummy file got created (function process_command in the same file):
if (n_infiles == 0
&& (print_subprocess_help || print_help_list || print_version))
{
/* Create a dummy input file, so that we can pass
the help option on to the various sub-processes. */
add_infile ("help-dummy", "c");
}

How to correct Knapsack compiling error MiniZinc?

What can I do for correcting errors in the following program
item= record( int: id, profit, weight);
set of item: All_Items ;
int :Max_Capacity;
var set of item: Selected_Items;
I have the following code for solving knapsack in MiniZinc, but it has many errors.
constraint sum([holds(X in Selected_Items)*X.weight | X in All_Items])=< Max_Capacity;
constraint Selected_Items >= All_Items;
maximize
sum([holds(S in Selected_Items)*S.profit |S in All_Items]);
Errors List
Compiling knapsack1.mzn
C:/Program Files/MiniZinc IDE (bundled)/examples/knapsack1.mzn:3.7-12:
item= record( int: id, profit, weight);
^^^^^^
Error: syntax error, unexpected record
C:/Program Files/MiniZinc IDE (bundled)/examples/knapsack1.mzn:11.45:
constraint sum([holds(X in Selected_Items)*X.weight | X in All_Items])=< Max_Capacity;
^
Error: syntax error, unexpected $undefined, expecting ]
C:/Program Files/MiniZinc IDE (bundled)/examples/knapsack1.mzn:15.1-8:
maximize
^^^^^^^^
Error: syntax error, unexpected maximize, expecting end of file
Process finished with non-zero exit code 1
Finished in 89msec
Although MiniZinc currently does not contain any record-types (read struct like types), they are a possibility for the future. To prevent breaking models in the future, the word record is therefore already a reserved keyword and can not be used in as an identifier in your model. Changing the name from record to something else will fix your problem.

Fortran error #5082: Syntax error, found IDENTIFIER when expecting one of: <END-OF-STATEMENT> ;

I am "making" a code.
The compilation with make fails producing this error
mpif90 -mkl -O3 -no-prec-div -fpp -openmp -xHost -DMPI -DEFTCOSMOMC -module ReleaseEFTMPI -IReleaseEFTMPI/ -c equations_EFT.f90 -o ReleaseEFTMPI/equations_EFT.o
equations_EFT.f90(267): error #5082: Syntax error, found IDENTIFIER 'EFTCAMBINITIALCONDITIONS' when expecting one of: <END-OF-STATEMENT> ;
module subroutine EFTCAMBInitialConditions( y, EV, tau )
--------------------------^
equations_EFT.f90(267): error #5082: Syntax error, found END-OF-STATEMENT when expecting one of: ( % [ . = =>
module subroutine EFTCAMBInitialConditions( y, EV, tau )
----------------------------------------------------------------^
equations_EFT.f90(271): error #6786: This is an invalid statement; an END [MODULE] statement is required.
end subroutine EFTCAMBInitialConditions
--------^
equations_EFT.f90(271): error #6758: This name is invalid; if a name is present, it must match the corresponding interface body name. [EFTCAMBINITIALCONDITIONS]
end subroutine EFTCAMBInitialConditions
-----------------------^
equations_EFT.f90(268): error #6457: This derived type name has not been declared. [EVOLUTIONVARS]
type(EvolutionVars) EV
-----------------^
equations_EFT.f90(269): error #6683: A kind type parameter must be a compile-time constant. [DL]
real(dl) :: y(EV%nvar)
-----------------^
equations_EFT.f90(269): error #6535: This variable or component must be of a derived or structure type [EV]
real(dl) :: y(EV%nvar)
--------------------------^
equations_EFT.f90(269): error #6460: This is not a field name that is defined in the encompassing structure. [NVAR]
real(dl) :: y(EV%nvar)
-----------------------------^
equations_EFT.f90(269): error #6223: A specification expression is invalid. [NVAR]
real(dl) :: y(EV%nvar)
-----------------------------^
equations_EFT.f90(270): error #6683: A kind type parameter must be a compile-time constant. [DL]
real(dl) :: tau
-----------------^
equations_EFT.f90(269): error #6279: A specification expression object must be a dummy argument, a COMMON block object, or an object accessible through host or use association [EV]
real(dl) :: y(EV%nvar)
--------------------------^
compilation aborted for equations_EFT.f90 (code 1)
I attach the snippet from equations_EFT.f90
interface
module subroutine EFTCAMBInitialConditions( y, EV, tau )
type(EvolutionVars) EV
real(dl) :: y(EV%nvar)
real(dl) :: tau
end subroutine EFTCAMBInitialConditions
end interface
Is there something wrong in this snippet? It is strange because this is distributed software, but I have literally just followed the instruction to make the code.
The code of the question is an example of using submodules, a feature newly introduced into Fortran in the 2008 revision. To compile this code you will need a compiler which understands this concept.
The GNU and Intel compilers are examples of such, but you will need an appropriate version.

error when compiling kernel with some new features

I am trying to compile kernel version 4.1 with some patches (adding some features to the GRO). I come from a hardware background and relatively new to network stack. I wish to know how to solve this problem or at least pointers to understand why it occurs.
This is what I did
# my temp location
mdkir kern
cd kern
# cloned the juggler and linux 4.1 tree
git clone https://github.com/gengyl08/juggler.git
wget https://www.kernel.org/pub/linux/kernel/v4.x/linux-4.1.tar.gz
tar -xvf linux-4.1.tar.gz
# copied just the essential files that were diffferent
cp juggler/linux-4.1/include/linux/netdevice.h linux-4.1/include/linux/netdevice.h
cp juggler/linux-4.1/include/linux/skbuff.h linux-4.1/include/linux/skbuff.h
cp juggler/linux-4.1/net/core/dev.c linux-4.1/net/core/dev.c
cp juggler/linux-4.1/net/core/net-sysfs.c linux-4.1/net/core/net-sysfs.c
cp juggler/linux-4.1/net/core/skbuff.c linux-4.1/net/core/skbuff.c
cp juggler/linux-4.1/net/ipv4/af_inet.c linux-4.1/net/ipv4/af_inet.c
cp juggler/linux-4.1/net/ipv4/tcp_offload.c linux-4.1/net/ipv4/tcp_offload.c
cd linux-4.1
make menuconfig # generated the default .config file
# building the kernel
time make
When I try to compile them, I get the following error
drivers/net/ethernet/agere/et131x.c: In function ‘nic_send_packet.constprop.43’:
include/linux/compiler.h:412:20: error: call to ‘__compiletime_assert_2439’ declared with attribute error: BUILD_BUG
prefix ## suffix(); \
^
include/linux/compiler.h:417:2: note: in expansion of macro ‘__compiletime_assert’
__compiletime_assert(condition, msg, prefix, suffix)
^
include/linux/compiler.h:429:2: note: in expansion of macro ‘_compiletime_assert’
_compiletime_assert(condition, msg, __compiletime_assert_, __LINE__)
^
include/linux/bug.h:50:37: note: in expansion of macro ‘compiletime_assert’
#define BUILD_BUG_ON_MSG(cond, msg) compiletime_assert(!(cond), msg)
^
include/linux/bug.h:74:2: note: in expansion of macro ‘BUILD_BUG_ON_MSG’
BUILD_BUG_ON_MSG(condition, "BUILD_BUG_ON failed: " #condition)
^
drivers/net/ethernet/agere/et131x.c:2439:2: note: in expansion of macro ‘BUILD_BUG_ON’
BUILD_BUG_ON(MAX_SKB_FRAGS + 1 > 23);
^
make[4]: *** [drivers/net/ethernet/agere/et131x.o] Error 1
make[3]: *** [drivers/net/ethernet/agere] Error 2
make[2]: *** [drivers/net/ethernet] Error 2
make[1]: *** [drivers/net] Error 2
make: *** [drivers] Error 2
real 22m3.067s
user 21m4.028s
sys 1m6.724s
It looks like MAX_SKB_FRAGS is too big and ethernet driver doesn't like it.
From drivers/net/ethernet/agere/et131x.c:
/* Part of the optimizations of this send routine restrict us to
* sending 24 fragments at a pass. In practice we should never see
* more than 5 fragments.
*/
/* nr_frags should be no more than 18. */
BUILD_BUG_ON(MAX_SKB_FRAGS + 1 > 23);
From the patches you're using:
linux-3.18.5/include/linux/skbuff.h:
#if (65536/PAGE_SIZE + 1) < 16
#define MAX_SKB_FRAGS 16UL
#else
#define MAX_SKB_FRAGS (65536/PAGE_SIZE + 1)
#endif
linux-4.1/include/linux/skbuff.h:
#if (65536/PAGE_SIZE + 1) < 45
#define MAX_SKB_FRAGS 45UL
#else
#define MAX_SKB_FRAGS (65536/PAGE_SIZE + 1)
#endif
Note the difference.
I haven't analyzed this code, but from a very first look I see some inconsistency there.
Replacing 45 back to 16 should do the trick. Of course, there might be a reason why the patch author picked a higher value.

Clang does not compile a g++ project

When trying to compile a g++ project with the clang compiler, there is a strange error showing up.
Here is the snippet of the source file:
std::set<TTransportNetworkId> l_transportNetworkIds;
SelectionResultContainer l_searchResult = p_repo.rootMoc() / LnAny("LNBTS") / LnAny("LNMME");
BOOST_FOREACH(const SelectionResult & l_lnmmeSR, l_searchResult)
{
const MoLnmme & l_lnmme = l_lnmmeSR;
l_transportNetworkIds.insert(*l_lnmme.transportNwId);
}
The error message is:
conditional expression is ambiguous; 'rvalue_probe<Rrom::DataRep::SelectionResultContainer>' can be converted to 'Rrom::DataRep::SelectionResultContainer' and vice versa
BOOST_FOREACH(const SelectionResult & l_lnmmeSR, l_searchResult)
Conditions are:
The file compiles fine with gcc_4.3.2
clang in version 3.2 throws the above error
Already tried to include the latest boost library which results in the same error
My guess is that clang handles rvalue conditions differently than this gcc version does.
clang is supposed to be a drop-in-replacement for gcc, so how can one get rid of this error without touching the source file?
Are there any options in clang which somehow disables these kind of errors?!
UPDATE:
I could create an example source file, which you can reproduce for yourself:
#include <vector>
#include <boost/foreach.hpp>
class A : public std::vector<int>
{
public:
template <class T>
operator const T &() const;
};
void foo(){
A colA;
int b = 1;
BOOST_FOREACH(b, colA)
{
;
}
}
When compiled with clang 3.2 the above error is raised, with some additional insights to where exactly the error occurs:
error: conditional expression is ambiguous; 'rvalue_probe<A>' can be converted to 'A' and vice versa BOOST_FOREACH(b, colA)
expanded from macro 'BOOST_FOREACH' f (boost::foreach_detail_::auto_any_t BOOST_FOREACH_ID(_foreach_col) = BOOST_FOREACH_CONTAIN(COL))
expanded from macro 'BOOST_FOREACH_CONTAIN' BOOST_FOREACH_EVALUATE(COL)
expanded from macro 'BOOST_FOREACH_EVALUATE' (true ? boost::foreach_detail_::make_probe((COL), BOOST_FOREACH_ID(_foreach_is_rvalue)) : (COL))
This code is compiled without errors with gcc_4.7.2.
Any ideas why the two compilers behave differently?
I found the solution in this document, see http://www.boost.org/doc/libs/1_43_0/boost/foreach.hpp
Snippet:
// Some compilers do not correctly implement the lvalue/rvalue conversion
// rules of the ternary conditional operator.
# if defined(BOOST_FOREACH_NO_RVALUE_DETECTION)
So, when providing a -DBOOST_FOREACH_NO_RVALUE_DETECTION definition option to clang, the error disappears.
Still the question remains whether gcc or clang is right or wrong on this point.

Resources