Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CIR] Relax the requirement for ternary operation #1168

Merged
merged 1 commit into from
Nov 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions clang/include/clang/CIR/Dialect/IR/CIROps.td
Original file line number Diff line number Diff line change
Expand Up @@ -805,8 +805,8 @@ def TernaryOp : CIR_Op<"ternary",
```
}];
let arguments = (ins CIR_BoolType:$cond);
let regions = (region SizedRegion<1>:$trueRegion,
SizedRegion<1>:$falseRegion);
let regions = (region AnyRegion:$trueRegion,
AnyRegion:$falseRegion);
let results = (outs Optional<CIR_AnyType>:$result);

let skipDefaultBuilders = 1;
Expand Down
15 changes: 15 additions & 0 deletions clang/test/CIR/CodeGen/ternary.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -fclangir -emit-cir -fno-clangir-call-conv-lowering %s -o %t.cir
// RUN: FileCheck --input-file=%t.cir %s --check-prefix=CIR

#include <stdarg.h>

double f1(int cond, int n, ...) {
va_list valist;
va_start(valist, n);
double res = cond ? va_arg(valist, double) : 0;
va_end(valist);
return res;
}

// Fine enough to check it passes the verifying.
// CIR: cir.ternary