Skip to content
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
2 changes: 1 addition & 1 deletion clang/lib/CIR/CodeGen/CIRGenCall.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ void CIRGenFunction::emitCallArg(CallArgList &args, const clang::Expr *e,

if (e->isGLValue()) {
assert(e->getObjectKind() == OK_Ordinary);
args.add(emitReferenceBindingToExpr(e), argType);
return args.add(emitReferenceBindingToExpr(e), argType);
}

bool hasAggregateEvalKind = hasAggregateEvaluationKind(argType);
Expand Down
49 changes: 49 additions & 0 deletions clang/test/CIR/CodeGen/forrange.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
// RUN: %clang_cc1 -std=c++17 -triple x86_64-unknown-linux-gnu -fclangir -emit-cir %s -o %t.cir
// RUN: FileCheck --input-file=%t.cir %s --check-prefix=CIR

struct Element {};
struct Container {};

Element *begin(Container &);
Element *end(Container &);

void for_range() {
Container c;
for (Element &e : c)
;
}

// CIR: cir.func @_Z5beginR9Container(!cir.ptr<!rec_Container>) -> !cir.ptr<!rec_Element>
// CIR: cir.func @_Z3endR9Container(!cir.ptr<!rec_Container>) -> !cir.ptr<!rec_Element

// CIR: cir.func @_Z9for_rangev()
// CIR: %[[C_ADDR:.*]] = cir.alloca !rec_Container{{.*}} ["c"]
// CIR: cir.scope {
// CIR: %[[RANGE_ADDR:.*]] = cir.alloca !cir.ptr<!rec_Container>{{.*}} ["__range1", init, const]
// CIR: %[[BEGIN_ADDR:.*]] = cir.alloca !cir.ptr<!rec_Element>{{.*}} ["__begin1", init]
// CIR: %[[END_ADDR:.*]] = cir.alloca !cir.ptr<!rec_Element>{{.*}} ["__end1", init]
// CIR: %[[E_ADDR:.*]] = cir.alloca !cir.ptr<!rec_Element>{{.*}} ["e", init, const]
// CIR: cir.store %[[C_ADDR]], %[[RANGE_ADDR]]
// CIR: %[[C_REF:.*]] = cir.load %[[RANGE_ADDR]]
// CIR: %[[BEGIN:.*]] = cir.call @_Z5beginR9Container(%[[C_REF]])
// CIR: cir.store %[[BEGIN]], %[[BEGIN_ADDR]]
// CIR: %[[C_REF2:.*]] = cir.load %[[RANGE_ADDR]]
// CIR: %[[END:.*]] = cir.call @_Z3endR9Container(%[[C_REF2]])
// CIR: cir.store %[[END]], %[[END_ADDR]]
// CIR: cir.for : cond {
// CIR: %[[BEGIN:.*]] = cir.load %[[BEGIN_ADDR]]
// CIR: %[[END:.*]] = cir.load %[[END_ADDR]]
// CIR: %[[CMP:.*]] = cir.cmp(ne, %[[BEGIN]], %[[END]])
// CIR: cir.condition(%[[CMP]])
// CIR: } body {
// CIR: %[[E:.*]] = cir.load deref %[[BEGIN_ADDR]]
// CIR: cir.store %[[E]], %[[E_ADDR]]
// CIR: cir.yield
// CIR: } step {
// CIR: %[[BEGIN:.*]] = cir.load %[[BEGIN_ADDR]]
// CIR: %[[STEP:.*]] = cir.const #cir.int<1>
// CIR: %[[NEXT:.*]] = cir.ptr_stride(%[[BEGIN]] {{.*}}, %[[STEP]] {{.*}})
// CIR: cir.store %[[NEXT]], %[[BEGIN_ADDR]]
// CIR: cir.yield
// CIR: }
// CIR: }