In general, the Attorney General is prohibited from granting an AOS if you have violated the underlying visa (8 USC 1255(c)):
https://uscode.house.gov/view.xhtml?req=granuleid:USC-prelim... (“subsection (a) [allowing AOS] shall not be applicable to… (8) any alien who was employed while the alien was an unauthorized alien, as defined in section 1324a(h)(3) of this title, or who has otherwise violated the terms of a nonimmigrant visa.”).
Subsection (d) allows the attorney general to grant an AOS notwithstanding subsection (c) where an immigrant enters j to a bona fide marriage during proceedings regarding their immigration status. But under subsection (a) the AOS is entirely at the “discretion” of the Attorney General.
Indeed, section 1255 doesn’t grant anyone legal status. It contains various provisions where an AOS must be denied. Then, it allows but does not require the Attorney General to grant an AOS under other circumstances.