[PATCH] D81678: Introduce noundef attribute at call sites for stricter poison analysis

Richard Smith - zygoloid via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Jul 21 14:26:33 PDT 2020


rsmith requested changes to this revision.
rsmith added a comment.
This revision now requires changes to proceed.

I'd like to see some testcases for the C++ side of this. The following things all seem like they might be interesting: passing and returning classes and unions, especially ones that aren't trivially-copyable, `nullptr_t`, pointers to members, `this` parameters, VTTs, the "complete object" flag for MS ABI constructors, the `this` return from constructors in the ARM ABI, parameters and return values of virtual adjustment thunks.



================
Comment at: clang/lib/CodeGen/CGCall.cpp:1892
+    return true;
+  if (QTy->isScalarType()) {
+    if (const ComplexType *Complex = dyn_cast<ComplexType>(QTy))
----------------
This includes `nullptr_t` (which is never ` noundef`) and member pointers (which are sometimes `noundef`, and you'll need to ask the `CXXABI` implementation if you don't want to conservatively return `false`).


================
Comment at: clang/lib/CodeGen/CGCall.cpp:2110
+      DetermineNoUndef(RetTy, getTypes(), DL, RetAI)) {
+    RetAttrs.addAttribute(llvm::Attribute::NoUndef);
+  }
----------------
This only applies in C++. In C, it's valid for a function to omit its `return` statement if the result value is unused, and in that case the returned value will legitimately be `undef`.

Even in C++, we're conservative about enforcing the constraint that functions return a proper value and control flow doesn't just fall off the bottom of the function. See the full set of checks here: https://github.com/llvm/llvm-project/blob/master/clang/lib/CodeGen/CodeGenFunction.cpp#L1322


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D81678/new/

https://reviews.llvm.org/D81678





More information about the llvm-commits mailing list