nickdesaulniers created this revision. Herald added a reviewer: NoQ. Herald added a project: All. nickdesaulniers requested review of this revision. Herald added a project: clang. Herald added a subscriber: cfe-commits.
Now that we support outputs from asm goto along indirect edges, we can remove/revert some code that was added to help warn about the previous limitation that outputs were not supported along indirect edges. Reverts code added in: commit 72aa619a7fe0 <https://reviews.llvm.org/rG72aa619a7fe0e2f90959b0614f6388c09aba8913> ("Warn of uninitialized variables on asm goto's indirect branch") But keeps+updates the tests. Link: https://github.com/llvm/llvm-project/issues/53562 Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D140508 Files: clang/lib/Analysis/UninitializedValues.cpp clang/test/Analysis/uninit-asm-goto.cpp
Index: clang/test/Analysis/uninit-asm-goto.cpp =================================================================== --- clang/test/Analysis/uninit-asm-goto.cpp +++ clang/test/Analysis/uninit-asm-goto.cpp @@ -9,9 +9,9 @@ return -1; } +// test2: Expect no diagnostics int test2(int x) { - int y; // expected-warning {{variable 'y' is used uninitialized whenever its declaration is reached}} - // expected-note@-1 {{initialize the variable}} + int y; if (x < 42) asm goto("" : "+S"(x), "+D"(y) : "r"(x) :: indirect_1, indirect_2); else @@ -20,29 +20,29 @@ indirect_1: return -42; indirect_2: - return y; // expected-note {{uninitialized use occurs here}} + return y; } +// test3: Expect no diagnostics int test3(int x) { - int y; // expected-warning {{variable 'y' is used uninitialized whenever its declaration is reached}} - // expected-note@-1 {{initialize the variable}} + int y; asm goto("" : "=&r"(y) : "r"(x) : : fail); normal: y += x; return y; if (x) { fail: - return y; // expected-note {{uninitialized use occurs here}} + return y; } return 0; } +// test4: Expect no diagnostics int test4(int x) { - int y; // expected-warning {{variable 'y' is used uninitialized whenever its declaration is reached}} - // expected-note@-1 {{initialize the variable}} + int y; goto forward; backward: - return y; // expected-note {{uninitialized use occurs here}} + return y; forward: asm goto("" : "=r"(y) : "r"(x) : : backward); return y; @@ -70,23 +70,40 @@ return -1; } +// test7: Expect no diagnostics. int test7(int z) { - int x; // expected-warning {{variable 'x' is used uninitialized whenever its declaration is reached}} - // expected-note@-1 {{initialize the variable 'x' to silence this warning}} + int x; if (z) asm goto ("":"=r"(x):::A1,A2); return 0; A1: A2: - return x; // expected-note {{uninitialized use occurs here}} + return x; } +// test8: Expect no diagnostics int test8() { - int x = 0; // expected-warning {{variable 'x' is used uninitialized whenever its declaration is reached}} - // expected-note@-1 {{variable 'x' is declared here}} + int x = 0; asm goto ("":"=r"(x):::A1,A2); return 0; A1: A2: - return x; // expected-note {{uninitialized use occurs here}} + return x; +} + +// test9: Expect no diagnostics +int test9 (int x) { + int y; + asm goto("": "=r"(y) :::out); + return 42; +out: + return y; +} + +int test10() { + int y; // expected-note {{initialize the variable 'y' to silence this warning}} + asm goto(""::::out); + return 42; +out: + return y; // expected-warning {{variable 'y' is uninitialized when used here}} } Index: clang/lib/Analysis/UninitializedValues.cpp =================================================================== --- clang/lib/Analysis/UninitializedValues.cpp +++ clang/lib/Analysis/UninitializedValues.cpp @@ -586,28 +586,6 @@ continue; } - if (AtPredExit == MayUninitialized) { - // If the predecessor's terminator is an "asm goto" that initializes - // the variable, then don't count it as "initialized" on the indirect - // paths. - CFGTerminator term = Pred->getTerminator(); - if (const auto *as = dyn_cast_or_null<GCCAsmStmt>(term.getStmt())) { - const CFGBlock *fallthrough = *Pred->succ_begin(); - if (as->isAsmGoto() && - llvm::any_of(as->outputs(), [&](const Expr *output) { - return vd == findVar(output).getDecl() && - llvm::any_of(as->labels(), - [&](const AddrLabelExpr *label) { - return label->getLabel()->getStmt() == B->Label && - B != fallthrough; - }); - })) { - Use.setUninitAfterDecl(); - continue; - } - } - } - unsigned &SV = SuccsVisited[Pred->getBlockID()]; if (!SV) { // When visiting the first successor of a block, mark all NULL @@ -820,7 +798,8 @@ // it's used on an indirect path, where it's not guaranteed to be // defined. if (const VarDecl *VD = findVar(Ex).getDecl()) - vals[VD] = MayUninitialized; + if (vals[VD] != Initialized) + vals[VD] = MayUninitialized; } }
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits