Board logo

标题: [求助]请问编译时出现的警告谢谢是何意思? [打印本页]

作者: 天涯倦客    时间: 2006-6-29 14:13     标题: [求助]请问编译时出现的警告谢谢是何意思?

我在用codewarrior for hcs12编译c源文件时.会出现如下的编译警告信息如下:


sp debug info incorrect because of optimization or inline assembler in main.c 6262


请问以上警告信息是什么意思?如果不理会这样的警告信息会有什么后果?谢谢了.


我用的单片机是DT128.


作者: 碧落星空    时间: 2006-6-29 14:50

我的程序有很多这个警告,不理会没有什么后果
作者: 天涯倦客    时间: 2006-6-29 14:53

呵呵,这样阿.不过我想了解下为什么会这样呢?看了这些警告很难受的.我在优化选项里面也屏蔽不掉.
作者: zhwdy81    时间: 2006-6-29 18:04

唉,每次出了警告我都是废了很大力气去消除
codewarrior警告实在是多啊
作者: 天涯倦客    时间: 2006-6-30 13:26

有没有人能帮忙解释一下上面的现象.
因为相同的函数.在codewarrior for hc08中可以编译没有警告.
但是在codewarrior for hcs16中却会出现
sp debug info incorrect because of optimization or inline assembler
作者: seuafu2005    时间: 2006-6-30 15:03

该警告编号C12056,可以查看CW的帮助文档查看详细的情况,对程序影响不大,可以disable掉它。详细解释我帖出来给你看看
Description:

The compiler investigates the generated code to detect the current SP value for every instruction. During this process, he detects that two different control flows generate different SP values for a single instruction.
This situation may arise because of different situations:
-inline assembler
In inline assembler code, it is legal to have this situation as long
as the stack is correct at the end of the inline assembler block.
-optimization
Especially because of the common code optimization -Of/-Onfx there are situations where this occurs in correct code.
It is impossible to generate correct debug info for this optimization in some cases.

The debugger may show local variables and the call chain incorrect for some parts in a function, for which this message occurs. But this message does not mean that the code generated is wrong in any sense.
Previous versions of the compiler did generate this warning in other situations, for which this version generates correct debug info.

Example (for C code):

void f(int);
void g(void);
void h(void);
void main(void) {
f(1); f(2); f(3);
h();
f(1); f(2); f(3);
g();
f(1); f(2);
}
The compiler first detects that "f(1); f(2); f(3);" occurs twice and puts this code separately.
The two code patters are replaced by a JSR to the new code.
This situation can be thought as the following non C pseudo code (C does not support local functions):
void main(void) {
void tmp0(void) {
f(1); f(2); f(3);

}
tmp0();
h();
tmp0();
g();
f(1); f(2);
}
In a next step, the compiler detects that the code "f(1); f(2);" does also occur twice. So
he generates a second internal function.
void main(void) {
void tmp1(void) {
f(1); f(2);
}
void tmp0(void) {
tmp1(); f(3);
}
tmp0();
h();
tmp0();
g();
tmp1();
}
Now the new code of the function tmp1 (actually tmp1 is not really a function, it is a part of main!) is called once directly from main and once indirectly by using tmp0. This two call chains now use a different amount of stack and the message

"C12056: SP debug info incorrect because of optimization or inline assembler"
is issued.

Example (for C inline assembler code)

void fun(long a, long b, int i);
#pragma NO_EXIT
void main1(void) { /* warning for debug info */
asm {
LDY #4
CLRA
CLRB
L0:
PSHD
DBNE Y, L0
JSR fun ; calls f with a == b == i== 0
LEAS 8,SP
RTS
}
}
The loop in main1 is looping 4 times and every time two bytes are pushed on the stack.
This loop let the compiler issue this message because at L0 different SP values occur at different times.
To avoid the inconveniences of such debug info, the same code could be written this way:

void main2(void) { /* debug info is OK */
asm {
CLRA
CLRB
PSHD
PSHD
PSHD
PSHD
JSR fun ; calls f with a == b == i== 0
LEAS 8,SP
RTS
}
}

Tips:

To debug try to switch the common code optimization off with -onf.
For inline assembler avoid this situation.


作者: 天涯倦客    时间: 2006-6-30 16:27

谢谢楼上!




欢迎光临 电子技术论坛_中国专业的电子工程师学习交流社区-中电网技术论坛 (http://bbs.eccn.com/) Powered by Discuz! 7.0.0