I was working with a old codebase where I encountered few line of code which was causing lot of repeated warnings during compilation.
#define EXAMPLE(_ptr) \
{ \
register uintptr_t *__sp __asm__("sp"); \
(_ptr[0]) = (uintptr_t) __sp; \
asm volatile("sw $a0,%0" : "=m" (_ptr[1])); \
//SOME OTHER CODE HERE
}
the warning was:
warning: ‘__sp’ may be used uninitialized in this function
Can anyone help me in understanding what is happening in this code block and how to remove this warning.
Related
I have written a macros but when i use the code i get expected identifier error.
Below is my macros
#define ITK(arguments) \
{ \
int iFail=0; \
iFail = arguments; \
if(iFail != ITK_ok) \
{ \
char* s; \
TC_write_syslog("Following Method Retruns error "#arguments "\n");\
TC_write_syslog("Error is in the line [%d] of the file ["__FILE__"]\n",[__LINE__]);\
EMH_ask_error_text(iFail,&s);\
TC_write_syslog("And the error is [%s]",s);\
if(s!=0) MEM_FREE(s);\
} \
}
As Davis Herring said the reason is your [__LINE__]
When you are lost and you do not see where is the error on that kind of case look at the code after the pre processing, for instance using g++ do g++ -E < other flags except -c > -o temp.cc and if you still don't see in temp.cc add line breaks in the interesting portion of code in temp.cc then compile temp.cc to look at compiler errors/warnings
Looks like a simple typo to me. You need to remove [ and ] here:
TC_write_syslog("Error is in the line [%d] of the file ["__FILE__"]\n",[__LINE__]);
// ^ ^
Note that instead of using printf's %d to insert __LINE__ into a string at runtime, you can convert __LINE__ to a string literal at compile-time:
#define STR(x) STR_(x)
#define STR_(x) #x
TC_write_syslog("Error is in the line " STR(__LINE__) " of the file ["__FILE__"]\n");
I copied a Big Int Library into my code and I'm having random errors in one of the classes. (The code is older)
One of my errors is in a define statement, not really sure how these work.
Everything under "tmpthis;" is giving an error.
#define DTRT_ALIASED(cond, op) \
if (cond) {\
BigUnsigned tmpThis;
tmpThis.op; //Error: no storage class or type specifier
*this = tmpThis; //Error: *this expected an identifier Error: No suitable conversion from "BigUnsigned" to "int" exists.
return; // Error: expected a declaration
} \
On top of that there are a few random if and for statements with the error "expected a declaration" and some variables with the error " no storage class or type specifier"
NOTE: these random errors also had instances where they were not errors also, it was inconsistent.
A bare-bones fix to the macro is:
#define DTRT_ALIASED(cond, op) \
if (cond) { \
BigUnsigned tmpThis; \
tmpThis.op; \
*this = tmpThis; \
return; \
}
This stands a chance of compiling when used in a function that doesn't return a value, if the reference to op in tmpThis.op makes sense to the compiler. It is somewhat peculiar (and limited) code, but there might be a use for it.
using g++ and compiling with -Waggregate-return
#define DOCTEST_CHECK(expr) \
do { \
_Pragma("GCC diagnostic push"); \
_Pragma("GCC diagnostic ignored \"-Waggregate-return\"");\
if(Result failed = (ExpressionDecomposer() << expr)) \
printf("%s\n", failed.m_decomposition.c_str()); \
_Pragma("GCC diagnostic pop"); \
} while(false)
DOCTEST_CHECK(true == false); // produces warnings
but the unrolled by hand version does not produce any warnings:
do {
_Pragma("GCC diagnostic push");
_Pragma("GCC diagnostic ignored \"-Waggregate-return\"");
if(Result failed = (ExpressionDecomposer() << true == false))
printf("%s\n", failed.m_decomposition.c_str());
_Pragma("GCC diagnostic pop");
} while(false);
Shouldn't the behavior be the same?
I don't think the Result and ExpressionDecomposer types matter - just classes.
I'm trying to get expression decomposition working like here (things have been renamed a bit).
EDIT: >> here << is a live demo of the problem using the lest library
My question is: why? how can I be warning free in the first case using the macro? I cannot afford silencing the warning globally.
These bugs look relevant:
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=55578
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=69543
So it might have to do with line number comparisons, or some similar issue within the parser, and it might be fixed in some future version.
You could try :
#define DOCTEST_CHECK(expr) \
do { \
_Pragma("GCC diagnostic push"); \
_Pragma("GCC diagnostic ignored \"-Waggregate-return\"");\
if(Result failed = (ExpressionDecomposer() << (expr))) \
printf("%s\n", failed.m_decomposition.c_str()); \
_Pragma("GCC diagnostic pop"); \
} while(false)
I have gone through all other similar issues, and yet I cannot understand why I am getting this error :
warning: suggest parentheses around arithmetic in operand of '|' [-Wparentheses]
&((~((PERIPHS_IO_MUX_FUNC)<<(PERIPHS_IO_MUX_FUNC_S)))) \
I am using xtensa-gcc. Following is the code (from ESP8266 SDK) :
#define PIN_FUNC_SELECT(PIN_NAME, FUNC) do { \
WRITE_PERI_REG(PIN_NAME, \
(READ_PERI_REG(PIN_NAME)) \
&((~((PERIPHS_IO_MUX_FUNC)<<(PERIPHS_IO_MUX_FUNC_S)))) \
|((((FUNC&BIT2)<<(2))|(FUNC&0x3))<<(PERIPHS_IO_MUX_FUNC_S)) ); \
} while (0)
The "&" and "|" leading on the last two lines both are at the same level of parentheses. The compiler is warning you that there can be some confusion by developers regarding precedence.
I am new to boost and I was trying to use the isomorphism.hpp file for directed graphs.
while trying to run the code, in the boost library file I am seeing the error
1>c:\boost_1_55_0\boost\graph\isomorphism.hpp(142): error C4703: potentially uninitialized local pointer variable 'v' used
1>c:\boost_1_55_0\boost\graph\isomorphism.hpp(147): error C4703: potentially uninitialized local pointer variable 'v' used
It is being thrown from here,
BGL_FORALL_VERTICES_T(v, G1, Graph1){
f[v] = graph_traits<Graph2>::null_vertex(); //error thrown here
}
This is defined in boost/graphs/iteration_macros.hpp as seen below:
#define BGL_FORALL_VERTICES_T(VNAME, GNAME, GraphType) \
for (std::pair<typename boost::graph_traits<GraphType>::vertex_iterator, \
typename boost::graph_traits<GraphType>::vertex_iterator> BGL_RANGE(__LINE__) = vertices(GNAME); \
BGL_FIRST(__LINE__) != BGL_LAST(__LINE__); BGL_FIRST(__LINE__) = BGL_LAST(__LINE__)) \
for (typename boost::graph_traits<GraphType>::vertex_descriptor VNAME; \
BGL_FIRST(__LINE__) != BGL_LAST(__LINE__) ? (VNAME = *BGL_FIRST(__LINE__), true):false; \
++BGL_FIRST(__LINE__))
Where do we need to define this? Is this a known issue?
1>c:\boost_1_55_0\boost\graph\isomorphism.hpp(142): error C4703: potentially uninitialized local pointer variable 'v' used
Given...
BGL_FORALL_VERTICES_T(v, G1, Graph1)
...and...
#define BGL_FORALL_VERTICES_T(VNAME, GNAME, GraphType)
...we know v is known as VNAME within the macro.
The condition on the outer loop is:
BGL_FIRST(__LINE__) != BGL_LAST(__LINE__)
The condition on the inner loop is:
BGL_FIRST(__LINE__) != BGL_LAST(__LINE__) ? (VNAME = *BGL_FIRST(__LINE__), true):false;
Given the inner loop doesn't run unless the outer loop condition is satisfied, we can simplify:
true ? (VNAME = *BGL_FIRST(__LINE__), true):false;
(VNAME = *BGL_FIRST(__LINE__), true) ;
Clearly VNAME is always assigned to and never used uninitialised. Your compiler's analysis is flawed, and you should disable the warning (only for this specific code if at all possible), otherwise turn off any treat-warnings-as-errors compiler option so your build doesn't break completely or try another compiler.
Go to
Project > "ProjectName" Properties > C/C++ > General
There you should switch "SDL checks" from Yes to No.
Visual Studio 2019 (platform toolset v142) with C++20 enabled and warning level 4 gives a lot of warnings. To silence them:
#pragma warning(push)
#pragma warning(disable: 4244) // '-=': conversion from '__int64' to 'int', possible loss of data
#pragma warning(disable: 4267) // '=' : conversion from 'size_t' to 'int', possible loss of data
#pragma warning(disable: 4456) // declaration of 'xxx' hides previous local declaration
#pragma warning(disable: 4701) // potentially uninitialized local variable 'xxx' used
#pragma warning(disable: 4703) // potentially uninitialized local pointer variable 'xxx' used
#include <boost/graph/isomorphism.hpp>
#pragma warning(pop)