The relevant provisions are subsections (a), (c), and (e) of 8 USC 1255: https://uscode.house.gov/view.xhtml?req=granuleid:USC-prelim...
Subsection (a) allows the “Attorney General, in his discretion” to grant an adjustment of status.
Subsection (c) categorically denies adjustment of status under certain conditions, including where someone has violated the terms of their visa. This takes away the Attorney General’s discretion to grant an adjustment. The adjustment must be denied.
Subsection (e) then makes subsection (c) inapplicable where the immigrant enters into a bona fide marriage during a legal proceeding regarding their immigrant status. It’s not correct to call this a “forgiveness,” because it doesn’t guarantee you any sort of legal status. Instead, it takes away what would otherwise be a categorical bar against an adjustment of status. That puts you back under subsection (a), where the decision is made by the “Attorney General, in his discretion.” The law says the Attorney can grant you the adjustment of status, not that he must. Under the law, the Attorney General can still categorically deny any adjustments under those circumstances.