[llvm] [llvm] Use StringRef::{starts,ends}_with (NFC) (PR #74956)

Felipe de Azevedo Piovezan via llvm-commits llvm-commits at lists.llvm.org
Mon Dec 11 03:20:10 PST 2023


felipepiovezan wrote:

> > > LGTM - I couldn't see any clang-format warnings that were particularly severe (just code alignment etc.) - its up to you if you format them or not.
> > 
> > 
> > Most of those are about 80 characters/line. IMO we should not be introducing code that is not clang-format clean, just like with any other PR
> 
> @felipepiovezan How can you tell? The bot's stderr doesn't seem to tell you and the ones I could see were the typical cases where lines had been manually indented to align.

Looking at some random output from the bot:

```
   if ((OpcodeName.starts_with("POP") && !OpcodeName.starts_with("POPCNT")) ||
-      OpcodeName.starts_with("PUSH") || OpcodeName.starts_with("ADJCALLSTACK") ||
-      OpcodeName.starts_with("LEAVE"))
+      OpcodeName.starts_with("PUSH") ||
+      OpcodeName.starts_with("ADJCALLSTACK") || OpcodeName.starts_with("LEAVE"))
```

The line where `PUSH` is now has 81 characters.

```
              (Mnemonic.starts_with("vcvt") && !Mnemonic.starts_with("vcvta") &&
-              !Mnemonic.starts_with("vcvtn") && !Mnemonic.starts_with("vcvtp") &&
+              !Mnemonic.starts_with("vcvtn") &&
+              !Mnemonic.starts_with("vcvtp") &&
```

Same here for the line where `vcvtn` is.


And then there are some cases where the previous code was already offending the formatter:

```
-    if (GV.getName().starts_with("llvm.") ||
-        GV.getName().starts_with(".llvm."))
+    if (GV.getName().starts_with("llvm.") || GV.getName().starts_with(".llvm."))
       continue;
 ```

These ones we can probably ignore, but if we're changing those lines anyway.. might as well make the formatter happy.
Maybe in the past this was done manually to make code aligned, but manual alignment without the appropriate pragmas will keep perpetuating false-positives from the tools


https://github.com/llvm/llvm-project/pull/74956


More information about the llvm-commits mailing list