[llvm] [C API] Add function to create constantRange attributes to C API (PR #90505)
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Thu May 2 18:48:17 PDT 2024
================
@@ -308,4 +310,36 @@ TEST(Attributes, RemoveParamAttributes) {
EXPECT_EQ(AL.getNumAttrSets(), 0U);
}
+TEST(Attributes, ConstantRangeAttributeCAPI) {
+ LLVMContext C;
+ {
+ const unsigned NumBits = 8;
+ const uint64_t LowerWords[] = {0};
+ const uint64_t UpperWords[] = {42};
+
+ auto Range =
+ ConstantRange(APInt(NumBits, ArrayRef<uint64_t>(LowerWords, 1)),
+ APInt(NumBits, ArrayRef<uint64_t>(UpperWords, 1)));
----------------
nikic wrote:
```suggestion
ConstantRange Range(APInt(NumBits, ArrayRef<uint64_t>(LowerWords, 1)),
APInt(NumBits, ArrayRef<uint64_t>(UpperWords, 1)));
```
is how you'd usually write this in C++...
I think you can probably also use `ArrayRef(LowerWords)` here, there should be a ctor for plain arrays and a template deduction guide.
https://github.com/llvm/llvm-project/pull/90505
More information about the llvm-commits
mailing list