Index: cfe/trunk/lib/Sema/SemaExpr.cpp =================================================================== --- cfe/trunk/lib/Sema/SemaExpr.cpp +++ cfe/trunk/lib/Sema/SemaExpr.cpp @@ -13477,9 +13477,22 @@ case BuiltinType::PseudoObject: return checkPseudoObjectRValue(E); - case BuiltinType::BuiltinFn: + case BuiltinType::BuiltinFn: { + // Accept __noop without parens by implicitly converting it to a call expr. + auto *DRE = dyn_cast(E->IgnoreParenImpCasts()); + if (DRE) { + auto *FD = cast(DRE->getDecl()); + if (FD->getBuiltinID() == Builtin::BI__noop) { + E = ImpCastExprToType(E, Context.getPointerType(FD->getType()), + CK_BuiltinFnToFnPtr).get(); + return new (Context) CallExpr(Context, E, None, Context.IntTy, + VK_RValue, SourceLocation()); + } + } + Diag(E->getLocStart(), diag::err_builtin_fn_use); return ExprError(); + } // Everything else should be impossible. #define BUILTIN_TYPE(Id, SingletonId) \ Index: cfe/trunk/test/CodeGen/builtin-ms-noop.cpp =================================================================== --- cfe/trunk/test/CodeGen/builtin-ms-noop.cpp +++ cfe/trunk/test/CodeGen/builtin-ms-noop.cpp @@ -1,13 +1,30 @@ -// RUN: %clang_cc1 -fms-extensions -triple %itanium_abi_triple -emit-llvm %s -o - | FileCheck %s +// RUN: %clang_cc1 -fms-extensions -triple x86_64-unknown-unknown -emit-llvm %s -o - | FileCheck %s -class A { - public: +struct A { ~A() {} }; -int f() { -// CHECK: @_Z1fv +extern "C" int f() { +// CHECK: define i32 @f() // CHECK-NOT: call void @_ZN1AD1Ev // CHECK: ret i32 0 return __noop(A()); }; + +extern "C" int g() { + return __noop; +// CHECK: define i32 @g() +// CHECK: ret i32 0 +} + +extern "C" int h() { + return (__noop); +// CHECK: define i32 @h() +// CHECK: ret i32 0 +} + +extern "C" int i() { + return __noop + 1; +// CHECK: define i32 @i() +// CHECK: ret i32 1 +}