This is an archive of the discontinued LLVM Phabricator instance.

[AST] Support Bool type in va_arg
AbandonedPublic

Authored by Qfrost911 on Oct 20 2022, 8:54 PM.

Details

Summary
void test(int place_holder, ...)
{
	va_list args;
	va_start(args, place_holder);
	bool unicode = va_arg(args, bool);
}

Currently, if the second argument is "Bool", it will be casted to "int".

This patch add support for Bool type

Diff Detail

Event Timeline

Qfrost911 created this revision.Oct 20 2022, 8:54 PM
Herald added a project: Restricted Project. · View Herald TranscriptOct 20 2022, 8:54 PM
Qfrost911 requested review of this revision.Oct 20 2022, 8:54 PM
Herald added a project: Restricted Project. · View Herald TranscriptOct 20 2022, 8:54 PM
Herald added a subscriber: cfe-commits. · View Herald Transcript

Currently, if the second argument is "Bool", it will be casted to "int".

That behavior is required by the standard, which is why we give a warning about it being undefined behavior due to the promotion. For C, see C2x 7.16.1.1p2 ("If type is not compatible with the type of the actual next argument (as promoted according to the default argument promotions), the behavior is undefined, except for the following cases: ..." and none of the cases apply to bool.) and for C++, see https://eel.is/c++draft/cstdarg.syn#1.sentence-4 which says the same thing in different words.

You'll see the same kind of UB if you try to use short instead of bool: https://godbolt.org/z/Kz95vbaY4

Qfrost911 abandoned this revision.Oct 21 2022, 5:51 AM

I see, thank you very much.

I see, thank you very much.

Thank you for trying to improve things in Clang! Even if this wasn't the right approach, the effort is still appreciated. :-) BTW, we have been trying to tag issues in GitHub with the "good first issue" label if we think it's a good way to get introduced to the code base. If you're looking for a way to help contribute small fixes to Clang. You can see the list here: https://github.com/llvm/llvm-project/issues?q=is%3Aissue+is%3Aopen+label%3A%22good+first+issue%22