brintos

brintos / llvm-project-archived public Read only

0
0
Text · 2.6 KiB · 4c7812c Raw
104 lines · cpp
1// RUN: %clang_cc1 -std=c++20 -triple x86_64-unknown-linux-gnu -fclangir -emit-cir %s -o - 2>&1 | FileCheck %s2 3// Test anonymous namespace.4namespace {5  int g1 = 1;6 7  void f1(void) {}8}9 10 11// Test named namespace.12namespace test {13  int g2 = 2;14  void f2(void);15 16  // Test nested namespace.17  namespace test2 {18    int g3 = 3;19    void f3(void);20  }21}22 23// CHECK-DAG: cir.global "private" internal dso_local @_ZN12_GLOBAL__N_12g1E = #cir.int<1> : !s32i24// CHECK-DAG: cir.global external @_ZN4test2g2E = #cir.int<2> : !s32i25// CHECK-DAG: cir.global external @_ZN4test5test22g3E = #cir.int<3> : !s32i26// CHECK-DAG: cir.func{{.*}} @_ZN12_GLOBAL__N_12f1Ev()27// CHECK-DAG: cir.func{{.*}} @_ZN4test2f2Ev()28// CHECK-DAG: cir.func{{.*}} @_ZN4test5test22f3Ev()29 30using namespace test;31 32// Test global function.33int f4(void) {34    f1();35    f2();36    test2::f3();37    return g1 + g2 + test2::g3;38}39 40// The namespace gets added during name mangling, so this is wrong but expected.41// CHECK: cir.func{{.*}} @_Z2f4v()42// CHECK:   cir.call @_ZN12_GLOBAL__N_12f1Ev()43// CHECK:   cir.call @_ZN4test2f2Ev()44// CHECK:   cir.call @_ZN4test5test22f3Ev()45// CHECK:   %[[G1_ADDR:.*]] = cir.get_global @_ZN12_GLOBAL__N_12g1E : !cir.ptr<!s32i>46// CHECK:   %[[G1_VAL:.*]] = cir.load{{.*}} %[[G1_ADDR]] : !cir.ptr<!s32i>, !s32i47// CHECK:   %[[G2_ADDR:.*]] = cir.get_global @_ZN4test2g2E : !cir.ptr<!s32i>48// CHECK:   %[[G2_VAL:.*]] = cir.load{{.*}} %[[G2_ADDR]] : !cir.ptr<!s32i>, !s32i49// CHECK:   %[[SUM:.*]] = cir.binop(add, %[[G1_VAL]], %[[G2_VAL]]) nsw : !s32i50// CHECK:   %[[G3_ADDR:.*]] = cir.get_global @_ZN4test5test22g3E : !cir.ptr<!s32i>51// CHECK:   %[[G3_VAL:.*]] = cir.load{{.*}} %[[G3_ADDR]] : !cir.ptr<!s32i>, !s32i52// CHECK:   %[[SUM2:.*]] = cir.binop(add, %[[SUM]], %[[G3_VAL]]) nsw : !s32i53 54using test2::f3;55using test2::g3;56 57int f5() {58  f3();59  return g3;60}61 62// CHECK: cir.func{{.*}} @_Z2f5v()63// CHECK:   cir.call @_ZN4test5test22f3Ev()64// CHECK:   %[[G3_ADDR:.*]] = cir.get_global @_ZN4test5test22g3E : !cir.ptr<!s32i>65// CHECK:   %[[G3_VAL:.*]] = cir.load{{.*}} %[[G3_ADDR]] : !cir.ptr<!s32i>, !s32i66 67namespace test3 {68  struct S {69    int a;70  } s;71}72 73using test3::s;74 75int f6() {76  return s.a;77}78 79// CHECK: cir.func{{.*}} @_Z2f6v()80// CHECK:   cir.get_global @_ZN5test31sE : !cir.ptr<!rec_test33A3AS>81// CHECK:   cir.get_member %{{.*}}[0] {name = "a"}82 83int shadowedFunc() {84  return 3;85}86 87namespace shadow {88  using ::shadowedFunc;89}90 91void f7() {92  shadow::shadowedFunc();93}94 95// CHECK: cir.func{{.*}} @_Z2f7v()96 97namespace test_alias = test;98 99int f8() {100  return test_alias::g2;101}102 103// CHECK: cir.func{{.*}} @_Z2f8v()104