Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ccache 无法正确处理宏参数中的换行 #2467

Closed
BenzzzX opened this issue Jun 16, 2022 · 9 comments
Closed

ccache 无法正确处理宏参数中的换行 #2467

BenzzzX opened this issue Jun 16, 2022 · 9 comments
Labels
Milestone

Comments

@BenzzzX
Copy link

BenzzzX commented Jun 16, 2022

Xmake Version

2.6.7 dev

Operating System Version and Architecture

21H2 MSVC 17

Describe Bug

复现最小示例
main.cpp

#define QUICKCPPLIB_PREVIOUS_COMMIT_UNIQUE 560ac657
#define QUICKCPPLIB_SIGNAL_GUARD_SYMBOL2(a, b, c) a #b c
#define QUICKCPPLIB_SIGNAL_GUARD_SYMBOL1(a, b, c) QUICKCPPLIB_SIGNAL_GUARD_SYMBOL2(a, b, c)
#define QUICKCPPLIB_SIGNAL_GUARD_SYMBOL(a, b) QUICKCPPLIB_SIGNAL_GUARD_SYMBOL1(a, QUICKCPPLIB_PREVIOUS_COMMIT_UNIQUE, b)
#pragma comment(linker,                                                                                                                                        \
                QUICKCPPLIB_SIGNAL_GUARD_SYMBOL("/alternatename:?RaiseException@win32@detail@signal_guard@_", "@quickcpplib@@YAXKKKPEB_K@Z=RaiseException"))
#pragma comment(linker, QUICKCPPLIB_SIGNAL_GUARD_SYMBOL("/alternatename:?SetUnhandledExceptionFilter@win32@detail@signal_guard@_",                             \
                                                        "@quickcpplib@@YAP6AJPEAU_EXCEPTION_POINTERS@12345@@ZP6AJ0@Z@Z=SetUnhandledExceptionFilter"))

int main()
{
    return 0;
}

xmake.lua

set_project("test")
set_languages("c11", "cxx17")
target("test")
    set_kind("binary")
    add_files("main.cpp")

ccache生成的文件:

#line 1 "main.cpp"





#pragma comment(linker,                                                                                                                                        \
                "/alternatename:?RaiseException@win32@detail@signal_guard@_" "560ac657" "@quickcpplib@@YAXKKKPEB_K@Z=RaiseException")
#pragma comment(linker, 
"/alternatename:?SetUnhandledExceptionFilter@win32@detail@signal_guard@_" "560ac657" "@quickcpplib@@YAP6AJPEAU_EXCEPTION_POINTERS@12345@@ZP6AJ0@Z@Z=SetUnhandledExceptionFilter")

int main()
{
    return 0;
}

其中第二个 #pragma 命令换行了行尾却没有 '\' 换行符,导致编译失败,输出:

error: main.cpp.cpp
main.cpp(8): warning C4081: 应输入“字符串”;找到“newline”
main.cpp(9): error C2059: 语法错误:“字符串”
main.cpp(9): error C2059: 语法错误:“)”
main.cpp(12): error C2143: 语法错误: 缺少“;”(在“{”的前面)
main.cpp(12): error C2447: “{”: 缺少函数标题(是否是老式的形式表?)

也就是 #pragma 命令内部的换行能被正确处理,而宏参数内部的换行不能被正确处理。

Expected Behavior

正确处理宏参数内部的换行

Project Configuration

No response

Additional Information and Error Logs

No response

@BenzzzX BenzzzX added the bug label Jun 16, 2022
@waruqi
Copy link
Member

waruqi commented Jun 16, 2022

我这也改不了 msvc 预处理内部逻辑,如果前期对 预处理文件做文本替换修复,太影响性能,那就失去 ccache 的意义嘞。。

目前唯一的兼容方式就是,先尝试编译 预处理文件,如果失败了,再去尝试编译原始代码。

@BenzzzX
Copy link
Author

BenzzzX commented Jun 16, 2022

那要不要去给 msvc 官方提一下 issue

@waruqi
Copy link
Member

waruqi commented Jun 16, 2022

那要不要去给 msvc 官方提一下 issue

msvc 不开源,你去哪提 issues = =

而且即使他们几年后修了,历史版本还得一样要兼容

@BenzzzX
Copy link
Author

BenzzzX commented Jun 16, 2022

这个23333 https://developercommunity.visualstudio.com/report?entry=problem
或者使用一个第三方的预处理器?

@waruqi
Copy link
Member

waruqi commented Jun 16, 2022

或者使用一个第三方的预处理器?

那还得用户额外安装依赖,而且第三方兼容性怎样也不好说。。那还不如遇到问题了,自动回退到直接编译了,也就小概率事件,几不影响 ccache 优化,也不影响编译结果

@BenzzzX
Copy link
Author

BenzzzX commented Jun 16, 2022

确实,先实现一个 fallback 策略比较稳妥吧。有没有可能分文件设置,不然一个文件出现问题整个工程都没法用 ccache 了。

@waruqi
Copy link
Member

waruqi commented Jun 16, 2022

确实,先实现一个 fallback 策略比较稳妥吧。有没有可能分文件设置,不然一个文件出现问题整个工程都没法用 ccache 了。

不用设置,编译错误了,自动回退到原始文件编译就行了,啥也不用改。

@waruqi
Copy link
Member

waruqi commented Jun 16, 2022

我改进过了,你再试试,更新到 dev

xmake update -s dev

@waruqi waruqi added this to the v2.6.8 milestone Jun 16, 2022
@BenzzzX
Copy link
Author

BenzzzX commented Jun 16, 2022

可以通过编译了

@waruqi waruqi closed this as completed Jun 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants