[all-commits] [llvm/llvm-project] e51102: [MLIR] Make More Specific Function Header For Stri...

Andrew Luo via All-commits all-commits at lists.llvm.org
Tue Oct 15 10:39:07 PDT 2024


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: e511026bf04b9d10d91d107174037b48f531278a
      https://github.com/llvm/llvm-project/commit/e511026bf04b9d10d91d107174037b48f531278a
  Author: Andrew Luo <andrew.zhao.luo at gmail.com>
  Date:   2024-10-15 (Tue, 15 Oct 2024)

  Changed paths:
    M mlir/include/mlir/IR/Diagnostics.h
    M mlir/unittests/IR/CMakeLists.txt
    A mlir/unittests/IR/Diagnostic.cpp

  Log Message:
  -----------
  [MLIR] Make More Specific Function Header For StringLiteral Optimization in `Diagnostic` (#112154)

Diagnostic stores various notes/error messages which might help the user
in debugging. For the most part, the `Diagnostic` when receiving an
error message will copy and own the contents of the string.

However, there is one optimization where given a `const char*`, the
class will assume this is a StringLiteral which is immutable and
lifetime matches that of the entire program. As a result, instead of
copying the message in these cases the class will simply store the
underlying pointer.

This is problematic since `const char*` is not specific enough to always
imply a StringLiteral which can lead to bugs, e.g. if the underlying
pointer is freed before the diagnostic reports.

We solve this problem by choosing a more specific function signature.
While not full-proof, this should cover a lot more cases.

A potentially better alternative is just deleting this special handling
of string literals, but I am unsure of the implications (it does sound
safe to do however with a negligble impact on performance).



To unsubscribe from these emails, change your notification settings at https://github.com/llvm/llvm-project/settings/notifications


More information about the All-commits mailing list