[all-commits] [llvm/llvm-project] da61cb: [Attributes] Make attribute addition behavior cons...

Nikita Popov via All-commits all-commits at lists.llvm.org
Wed Jan 19 03:05:47 PST 2022


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: da61cb019eb2aa624862212960be3609a744b26e
      https://github.com/llvm/llvm-project/commit/da61cb019eb2aa624862212960be3609a744b26e
  Author: Nikita Popov <npopov at redhat.com>
  Date:   2022-01-19 (Wed, 19 Jan 2022)

  Changed paths:
    M llvm/include/llvm/IR/Attributes.h
    M llvm/lib/IR/Attributes.cpp
    M llvm/test/Transforms/Inline/ret_attr_update.ll
    M llvm/test/Transforms/InstCombine/deref-alloc-fns.ll

  Log Message:
  -----------
  [Attributes] Make attribute addition behavior consistent

Currently, the behavior when adding an attribute with the same key
as an existing attribute is inconsistent, depending on the type of
the attribute and the method used to add it. When going through
AttrBuilder::addAttribute(), the new attribute always overwrites
the old one. When going through AttrBuilder::merge() the new
attribute overwrites the existing one if it is a string attribute,
but keeps the existing one for int and type attributes. One
particular API also asserts that you can't overwrite an align
attribute, but does not handle any of the other int, type or string
attributes.

This patch makes the behavior consistent by always overwriting with
the new attribute, which is the behavior I would intuitively expect.
Two tests are affected, which now make a different (but equally
valid) choice. Those tests could be improved by taking the maximum
deref bytes, but I haven't bothered with that, since this is testing
a degenerate case -- the important bit is that it doesn't crash.

Differential Revision: https://reviews.llvm.org/D117552




More information about the All-commits mailing list