diff --git a/clang/lib/Analysis/UninitializedValues.cpp b/clang/lib/Analysis/UninitializedValues.cpp --- a/clang/lib/Analysis/UninitializedValues.cpp +++ b/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(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; } } diff --git a/clang/test/Analysis/uninit-asm-goto.cpp b/clang/test/Analysis/uninit-asm-goto.cpp --- a/clang/test/Analysis/uninit-asm-goto.cpp +++ b/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}} }