[clang] nonblocking/nonallocating attributes (was: nolock/noalloc) (PR #84983)

Chris Apple via cfe-commits cfe-commits at lists.llvm.org
Fri May 3 10:59:05 PDT 2024


cjappl wrote:


Hi @dougsonos,

Just starting to integrate our two changes and noticing a possible bug here.

Issue: `blocking(false)` does not seem to resolve to `nonblocking`

## Streps to repro:
1. Have an example like
```
int main() [[clang::blocking(false)]]
{
    return 0;
}
```
2. (optional, if you can't get diagnostics another way) Apply this patch to llvm, and recompile clang
```
diff --git a/clang/lib/CodeGen/CGCall.cpp b/clang/lib/CodeGen/CGCall.cpp
index 69548902dc43..3047ed1e1887 100644
--- a/clang/lib/CodeGen/CGCall.cpp
+++ b/clang/lib/CodeGen/CGCall.cpp
@@ -2404,6 +2404,15 @@ void CodeGenModule::ConstructAttributeList(StringRef Name,
           FuncAttrs.addAttribute(llvm::Attribute::NoReturn);
         NBA = Fn->getAttr<NoBuiltinAttr>();
       }
+
+      llvm::raw_fd_ostream stream(1, true);
+      const auto effects = Fn->getFunctionEffects();
+      if (not effects.empty())
+      {
+        stream << "Function: " << Fn->getNameAsString().c_str() << "\n";
+        Fn->getFunctionEffects().dump(stream);
+        stream << "\n";
+      }
     }
 
     if (isa<FunctionDecl>(TargetDecl) || isa<VarDecl>(TargetDecl)) {
```

3. Compile aforementioned main file with the new perf-constraints clang

## Observed 

`blocking(false)` incorrectly resolves to `blocking`, when it should be `nonblocking`

```
> ninja
[1/2] Building CXX object CMakeFiles/MyExecutable.dir/main.cpp.o
Function: main
Effects{blocking}
...
```

All the other (non)blocking conditionals seem to work as intended.

1. `nonblocking(true)` -- should resolve to nonblocking ✅
```
Function: main
Effects{nonblocking}
```
2. `nonblocking(false)` -- should resolve to blocking ✅
```
Function: main
Effects{blocking}
```
3. `blocking(true)` -- should resolve to blocking ✅
```
Function: main
Effects{blocking}
```

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


More information about the cfe-commits mailing list