mirror of
https://github.com/capstone-engine/llvm-capstone.git
synced 2024-12-13 19:24:21 +00:00
[clang] fix -Wuninitialized for asm goto outputs on indirect edges.
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 some code added in: commit72aa619a7f
("Warn of uninitialized variables on asm goto's indirect branch") commit3a604fdbcd
("[Clang][CFG] check children statements of asm goto") But keeps+updates the tests. Link: https://github.com/llvm/llvm-project/issues/53562 Reviewed By: void Differential Revision: https://reviews.llvm.org/D140508
This commit is contained in:
parent
329ef60f3e
commit
af6656338d
@ -586,28 +586,6 @@ public:
|
||||
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 @@ void TransferFunctions::VisitGCCAsmStmt(GCCAsmStmt *as) {
|
||||
// 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;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -9,9 +9,9 @@ int test1(int x) {
|
||||
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 @@ int test2(int x) {
|
||||
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 @@ indirect:
|
||||
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}}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user