Index: lib/Basic/Targets.cpp =================================================================== --- lib/Basic/Targets.cpp +++ lib/Basic/Targets.cpp @@ -2802,6 +2802,28 @@ initFeatureMap(llvm::StringMap &Features, DiagnosticsEngine &Diags, StringRef CPU, const std::vector &FeaturesVec) const override; + + void adjustTargetOptions(const CodeGenOptions &CGOpts, + TargetOptions &TargetOpts) const override { + StringRef Feature; + switch (CGOpts.NumRegisterParameters) { + case 1: + Feature = "+regparm1"; + break; + case 2: + Feature = "+regparm2"; + break; + case 3: + Feature = "+regparm3"; + break; + } + if (!Feature.empty()) + TargetOpts.Features.push_back(Feature); + + // Run Generic. + TargetInfo::adjustTargetOptions(CGOpts, TargetOpts); + } + bool hasFeature(StringRef Feature) const override; bool handleTargetFeatures(std::vector &Features, DiagnosticsEngine &Diags) override; Index: lib/CodeGen/MicrosoftCXXABI.cpp =================================================================== --- lib/CodeGen/MicrosoftCXXABI.cpp +++ lib/CodeGen/MicrosoftCXXABI.cpp @@ -729,7 +729,7 @@ CGM.CreateRuntimeFunction(FTy, "_CxxThrowException")); // _CxxThrowException is stdcall on 32-bit x86 platforms. if (CGM.getTarget().getTriple().getArch() == llvm::Triple::x86) - Fn->setCallingConv(llvm::CallingConv::X86_StdCall); + Fn->setCallingConv(llvm::CallingConv::X86_LibStdCall); return Fn; } Index: test/CodeGen/pr3997.c =================================================================== --- /dev/null +++ test/CodeGen/pr3997.c @@ -0,0 +1,15 @@ +// RUN: %clang_cc1 %s -triple i386-unknown-linux-gnu -mregparm 3 -emit-llvm -o - | FileCheck %s + +void *memcpy(void *dest, const void *src, unsigned int n); + +void use_builtin_memcpy(void *dest, const void *src, unsigned int n) { + __builtin_memcpy(dest, src, n); +} + +void use_memcpy(void *dest, const void *src, unsigned int n) { + memcpy(dest, src, n); +} + +//CHECK: define void @use_builtin_memcpy(i8* inreg %dest, i8* inreg %src, i32 inreg %n) #0 +//CHECK: define void @use_memcpy(i8* inreg %dest, i8* inreg %src, i32 inreg %n) #0 +//CHECK: #0 = {{.*}} "target-features"="{{[^"]*}}+regparm3,{{[^"]*}}"