From: Reid Kleckner Date: Fri, 11 Jul 2014 23:54:29 +0000 (+0000) Subject: Form a CallExpr from __noop without parens X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=9e492629b3f1b9856c89ea2cffa99e77ded4a38a;p=clang Form a CallExpr from __noop without parens MSVC accepts __noop without any trailing parens and treats it like a literal zero. We don't treat __noop as an integer literal, but now at least we can parse a naked __noop expression. Reviewers: rsmith Differential Revision: http://reviews.llvm.org/D4476 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@212860 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Sema/SemaExpr.cpp b/lib/Sema/SemaExpr.cpp index 67e839c7e5..8db782a7e2 100644 --- a/lib/Sema/SemaExpr.cpp +++ b/lib/Sema/SemaExpr.cpp @@ -13477,9 +13477,22 @@ ExprResult Sema::CheckPlaceholderExpr(Expr *E) { 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) \ diff --git a/test/CodeGen/builtin-ms-noop.cpp b/test/CodeGen/builtin-ms-noop.cpp index f5064fbf3c..76c6c139d0 100644 --- a/test/CodeGen/builtin-ms-noop.cpp +++ b/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 +}