Outputs from an asm goto block cannot be used on the indirect branch.
It's not supported and may result in invalid code generation.
Details
Diff Detail
- Repository
- rG LLVM Github Monorepo
- Build Status
Buildable 47181 Build 49996: arc lint + arc unit
Event Timeline
clang/lib/Analysis/UninitializedValues.cpp | ||
---|---|---|
590 | Is this more concise with llvm::any_of? | |
789 | Should we mark the vals MayUninitialized here, rather than below? Then I think we can remove the isAsmGoto check you added in getUninitUse? | |
clang/test/Analysis/uninit-asm-goto.cpp | ||
16 | I wonder if it's straight forward to make this a "maybe uninitialized" warning, instead of "is uninitialized?" Consider the inline asm: asm volatile goto("ja %l1; mov %0, 42" : "=r"(foo) ::: bar); Since we can't introspect the inline asm, we're not sure whether foo gets initialized by the asm or not (as the asm could transfer control flow back to the C label before any assignments to the output). Telling the user it's definitely uninitialized is technically correct in this case, but definitely incorrect for: asm volatile goto("mov %0, 42; ja %l1;" : "=r"(foo) ::: bar); | |
38 | Are we able to catch backwards branches from asm goto? (if so, would you mind please added that as an additional unit test). int foo; goto 1; 2: return foo; // should warn? 1: asm goto ("": "=r"(foo):::2); return foo; |
Use "any_of" and improve tests.
clang/test/Analysis/uninit-asm-goto.cpp | ||
---|---|---|
16 | The back end doesn't know how to generate code for a use in the indirect branches. It's really complicated and may result in code that doesn't actually work. I don't want to give off the impression that the code may work in these cases, because it would be essentially working by accident. | |
38 | Yes, we should be able to warn about this. I added a testcase. |
strange, the below test isn't warning for me with this patch applied:
$ clang -O2 foo.c -c $ cat foo.c int quux(void) { int y; asm volatile goto("ja %l1" : "=r"(y) ::: err); return y; err: return y; }
clang/lib/Analysis/UninitializedValues.cpp | ||
---|---|---|
789 | Ah, I see this was added in https://reviews.llvm.org/D69876. |
clang/lib/Analysis/UninitializedValues.cpp | ||
---|---|---|
798 | Can you walk me through the logic of this function? I would assume for changes to asm goto, the above early return would have been removed? Otherwise we seem to be changing the logic of the non-asm goto case? | |
clang/test/Analysis/uninit-asm-goto.cpp | ||
57 | bump |
clang/lib/Analysis/UninitializedValues.cpp | ||
---|---|---|
798 | Sure. If the variable hasn't been initialized by the time it gets to the asm goto, then we mark it as "potentially uninitialized" so that it's caught on the indirect branch. Uses on the default/fallthrough path should resolve to "initialized". I'll add a comment. |
Is this more concise with llvm::any_of?