This is an archive of the discontinued LLVM Phabricator instance.

Add std:: to begin and end in drop_begin
AbandonedPublic

Authored by kparzysz on Mar 6 2018, 2:05 PM.

Details

Reviewers
dblaikie
Summary

Compiling this code gives me "undeclared symbol" errors for begin and end in drop_begin:

if (const auto *A = dyn_cast<SCEVAddExpr>(R->getStart())) {
  if (const auto *C = dyn_cast<SCEVConstant>(A->getOperand(0))) {
    SmallVector<const SCEV*,2> Ops1(drop_begin(A->operands(), 1));
    const SCEV *NA = SE->getAddExpr(Ops1, A->getNoWrapFlags());
  }
}

This change is intended to fix that.

Diff Detail

Repository
rL LLVM

Event Timeline

kparzysz created this revision.Mar 6 2018, 2:05 PM

Unit tests would be good, and adding "std::" actually would break the ADL-based lookup possibilities (eg: the intent of the free-function begin/end API is to allow, say "my_namespace::vector" to be usable with "my_namespace::begin").

What we probably need is some kind of adl_begin/adl_end functions that wrap up this functionality for easy reuse throughout our STL helpers/wrapper/etc. Though I haven't given a lot of thought to how easy/hard that'd be to implement :/

bkramer added a subscriber: bkramer.Mar 6 2018, 2:13 PM

What we probably need is some kind of adl_begin/adl_end functions that wrap up this functionality for easy reuse throughout our STL helpers/wrapper/etc. Though I haven't given a lot of thought to how easy/hard that'd be to implement :/

We have adl_begin/adl_end in STLExtras.h

This actually works with trunk, fails with 5.0.1, so unless this needs to be addressed there, I'm going to abandon this. I'll just change the code that fails to compile.

This is the error:

/w/c/clang+llvm-5.0.1-x86_64-linux-gnu-ubuntu-14.04/bin/clang++ -c bre.cpp -I/w/c/clang+llvm-5.0.1-x86_64-linux-gnu-ubuntu-14.04/include  -fPIC -fvisibility-inlines-hidden -Werror=date-time -std=c++11 -Wall -W -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wmissing-field-initializers -pedantic -Wno-long-long -Wcovered-switch-default -Wnon-virtual-dtor -Wdelete-non-virtual-dtor -Wstring-conversion -ffunction-sections -fdata-sections -O3 -DNDEBUG  -fno-exceptions -fno-rtti -DLLVM_BUILD_GLOBAL_ISEL -D_GNU_SOURCE -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS
bre.cpp:9:35: error: no matching function for call to 'drop_begin'
  SmallVector<const SCEV*,2> Ops1(drop_begin(A->operands(), 1));
                                  ^~~~~~~~~~
/w/c/clang+llvm-5.0.1-x86_64-linux-gnu-ubuntu-14.04/include/llvm/ADT/iterator_range.h:63:52: note:
      candidate template ignored: substitution failure [with T =
      llvm::iterator_range<const llvm::SCEV *const *>]: use of undeclared
      identifier 'begin'
iterator_range<decltype(begin(std::declval<T>()))> drop_begin(T &&t, int n) {
                        ~~~~~                      ^
1 error generated.

Source file:

#include "llvm/ADT/iterator_range.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/Analysis/ScalarEvolution.h"
#include "llvm/Analysis/ScalarEvolutionExpressions.h"

using namespace llvm;

const SCEV *foo(ScalarEvolution *SE, const SCEVAddExpr *A) {
  SmallVector<const SCEV*,2> Ops1(drop_begin(A->operands(), 1));
  return SE->getAddExpr(Ops1, A->getNoWrapFlags());
}
kparzysz abandoned this revision.Mar 7 2018, 5:45 AM