Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
4 changes: 2 additions & 2 deletions compiler-rt/include/sanitizer/memprof_interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ void SANITIZER_CDECL __memprof_print_accumulated_stats(void);

/// User-provided default option settings.
///
/// You can set these options via the -memprof-default-options LLVM flag or
/// you can provide your own implementation of this function. See
/// You can set these options via the -memprof-runtime-default-options LLVM flag
/// or you can provide your own implementation of this function. See
/// memprof_flags.h for more info.
///
/// \returns Default options string.
Expand Down
4 changes: 2 additions & 2 deletions compiler-rt/lib/memprof/memprof_flags.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
// prior one:
// 1) by setting MEMPROF_DEFAULT_OPTIONS during the compilation of the MemProf
// runtime
// 2) by setting the LLVM flag -memprof-default-options during the compilation
// of your binary
// 2) by setting the LLVM flag -memprof-runtime-default-options during the
// compilation of your binary
// 3) by overriding the user-specified function __memprof_default_options()
// 4) by setting the environment variable MEMPROF_OPTIONS during runtime

Expand Down
3 changes: 3 additions & 0 deletions compiler-rt/test/memprof/TestCases/default_options.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
// RUN: %clangxx_memprof -O2 %s -o %t && %run %t 2>&1 | FileCheck %s

// Check that overriding __memprof_default_options() takes precedence over the LLVM flag
// RUN: %clangxx_memprof -O2 %s -o %t-flag -mllvm -memprof-runtime-default-options="verbosity=0 help=0" && %run %t-flag 2>&1 | FileCheck %s

const char *kMemProfDefaultOptions = "verbosity=1 help=1";

extern "C" const char *__memprof_default_options() {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the CHECK statement below will need to be updated to check verbosity=1 help=1 to verify the behaviour.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Available flags for MemProfiler: will only output if help=1, which is checked on line 6. So this indeed verifies the expected behavior.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for pointing that out.

Expand Down
2 changes: 1 addition & 1 deletion compiler-rt/test/memprof/TestCases/set_options.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// RUN: %clangxx_memprof %s -o %t-default
// RUN: %run %t-default | FileCheck %s --check-prefix=DEFAULT

// RUN: %clangxx_memprof %s -mllvm -memprof-default-options="print_text=true,log_path=stdout,atexit=false" -o %t
// RUN: %clangxx_memprof %s -mllvm -memprof-runtime-default-options="print_text=true,log_path=stdout,atexit=false" -o %t
// RUN: %run %t | FileCheck %s

#include <sanitizer/memprof_interface.h>
Expand Down
8 changes: 4 additions & 4 deletions llvm/lib/Transforms/Instrumentation/MemProfiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -167,9 +167,9 @@ static cl::opt<bool>
cl::Hidden, cl::init(false));

static cl::opt<std::string>
MemprofDefaultOptions("memprof-default-options",
cl::desc("The default memprof options"), cl::Hidden,
cl::init(""));
MemprofRuntimeDefaultOptions("memprof-runtime-default-options",
cl::desc("The default memprof options"),
cl::Hidden, cl::init(""));

extern cl::opt<bool> MemProfReportHintedSizes;

Expand Down Expand Up @@ -554,7 +554,7 @@ void createMemprofHistogramFlagVar(Module &M) {

void createMemprofDefaultOptionsVar(Module &M) {
Constant *OptionsConst = ConstantDataArray::getString(
M.getContext(), MemprofDefaultOptions, /*AddNull=*/true);
M.getContext(), MemprofRuntimeDefaultOptions, /*AddNull=*/true);
GlobalVariable *OptionsVar =
new GlobalVariable(M, OptionsConst->getType(), /*isConstant=*/true,
GlobalValue::WeakAnyLinkage, OptionsConst,
Expand Down
2 changes: 1 addition & 1 deletion llvm/test/Instrumentation/HeapProfiler/memprof-options.ll
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
; RUN: opt < %s -mtriple=x86_64-unknown-linux -passes='function(memprof),memprof-module' -S | FileCheck %s --check-prefixes=CHECK,EMPTY
; RUN: opt < %s -mtriple=x86_64-unknown-linux -passes='function(memprof),memprof-module' -S -memprof-default-options="verbose=1" | FileCheck %s --check-prefixes=CHECK,VERBOSE
; RUN: opt < %s -mtriple=x86_64-unknown-linux -passes='function(memprof),memprof-module' -S -memprof-runtime-default-options="verbose=1" | FileCheck %s --check-prefixes=CHECK,VERBOSE

define i32 @main() {
entry:
Expand Down
Loading